[Rails] Re: Paperclip Trouble - Not Writing to the Database

2010-08-10 Thread A. Leek
Parker Selbert wrote:
> There is a duality to Paperclip in that it is meant to process anything, 
> but the default processor (Thumbnail) is for images. I'm guessing the 
> versatility of it is why it doesn't do a hard check for ImageMagick 
> before it tries to process anything.
> 
> As far as the Paperclip Processor knows the command just fails, and 
> therefor processing fails, and therefore there is no image to link to. I 
> highly recommend writing a test that just checks that the path you're 
> using for ImageMagick exists. Something as simple as:
> 
> IMAGE_MAGICK_PATH = "/my/path/to/imagemagick"
> 
> def test_image_magick_is_installed
>   assert File.exist?(IMAGE_MAGICK_PATH)
> end
> 
> At least then you know that your install is working.

Well I tried that, and it comes back false... The error messages give 
the right path for ImageMagick, but they still fail on the identify 
command. I've tested "identify" from the command line, and it works 
fine. I'm pretty lost as to what to do now, Paperclip seems to 
understand there's ImageMagick in Program Files, they just don't want to 
talk to each other.

The images do get to a temp location in Local Settings\Temp, so some 
moving around is happening. Honestly, I'm just trying to get files 
uploaded in general, I'm only testing it on images because that's what 
all the guides are for and I wanted to have something working before I 
generalized. This is getting a lot more problematic than I expected. I 
guess the next thing to do is go to the Paperclip Google Group and see 
if they know anything.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Help on Route

2010-08-10 Thread Anubhaw Prakash
Tony Yin wrote:
> Anubhaw Prakash wrote:

>> Try this,
>> 
>> map.resources :controller_name, :collection => { :method_name => :get }
>> 
>> Thanks,
>> Anubhaw
> 
> hi Anubhaw, thanks for the reply, but that did not work. When I put that 
> in
> my routes.rb, I lost home index; but I can view index from 
> localhost:3000/site. But when I try to view localhost:3000/about it 
> gives me an error message Unknown action
> 
> No action responded to show. Actions: about, help, and index
> 
> So it appears something is not connecting, even though I specified the 
> action name and the action is defined in my controller.

Hi Tony,
Site is your controller name.
If you need to access a method from controller, the url should be like 
this
'localhost:3000/site/about'.

When you hit 'localhost:3000/site' the actual url is 
'localhost:3000/site/index'.
So in link to you need to specify controller name and action name.
If you need the url like localhost:3000/about, you need to specify 
following in route:-
map.connect '/about', :controller => 'site', :action => 'about'.

Thanks,
Anubhaw
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Use of :include option in find query

2010-08-10 Thread Robby Russell
The queries will likely be the same.. but you should check to see if
it loaded the company details _before_ you called @user.company.

You might try the following from script/console while tailing the log
file in another terminal.

ruby script/console
=>  User.find(2)

... check the log/development.log

=> User.find(2, :include => :company)

 check log/development.log

Good luck!

Cheers,
Robby



On Tue, Aug 10, 2010 at 10:21 PM, Mike Disuza  wrote:
> Hi I have written code like this
>
> 1) Without :include
> My code is :-
> def user_details
>   �...@user=user.find(params[:id])
>   �...@company=@user.company
> end
> Log Output:-
>
> Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11
> 10:51:34) [GET]
>  Parameters: {"id"=>"2"}
>  User Columns (1.0ms)   SHOW FIELDS FROM `users`
>  User Load (0.4ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
>  Company Load (0.4ms)   SELECT * FROM `companies` WHERE
> (`companies`.user_id = 2) LIMIT 1
> Rendering template within layouts/users
> Rendering users/user_details
> Completed in 65ms (View: 48, DB: 2) | 200 OK
> [http://localhost/user_xml?id=2]
>
> 2) With Include:-
>  def user_details
>   �...@user=user.find(params[:id], :include=>:company)
>   �...@company=@user.company
> end
> Log Output:-
> Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11
> 10:53:13) [GET]
>  Parameters: {"id"=>"2"}
>  User Columns (1.2ms)   SHOW FIELDS FROM `users`
>  User Load (0.5ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
>  Company Load (0.3ms)   SELECT * FROM `companies` WHERE
> (`companies`.user_id = 2) LIMIT 1
> Rendering template within layouts/users
> Rendering users/user_details
> Completed in 13ms (View: 2, DB: 2) | 200 OK
> [http://localhost/user_xml?id=2]
>
> If you look at the both o/p there is a query on company table in both
> the cases.
>
> What is the difference?
>
> Thanks,
> Mike
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Help on Route

2010-08-10 Thread Tony Yin
Anubhaw Prakash wrote:
> Tony Yin wrote:
>> hi, I'm new to rails, trying to setup a simple site, in my routes.rb I
>> have  map.root :controller => 'site' , and in my app/controller I have
>> defined site_controller.rb with action index and about. When I start up
>> the server, I can see my index on localhost:3000 as the default index,
>> but when I try to access localhost:3000/about, it gives my a routing
>> error saying "No route matches "/about" with {:method=>:get}".
>> Please help
>> 
>> Thank you
> 
> 
> Try this,
> 
> map.resources :controller_name, :collection => { :method_name => :get }
> 
> Thanks,
> Anubhaw

hi Anubhaw, thanks for the reply, but that did not work. When I put that 
in
my routes.rb, I lost home index; but I can view index from 
localhost:3000/site. But when I try to view localhost:3000/about it 
gives me an error message Unknown action

No action responded to show. Actions: about, help, and index

So it appears something is not connecting, even though I specified the 
action name and the action is defined in my controller.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Help on Route

2010-08-10 Thread Anubhaw Prakash
Tony Yin wrote:
> hi, I'm new to rails, trying to setup a simple site, in my routes.rb I
> have  map.root :controller => 'site' , and in my app/controller I have
> defined site_controller.rb with action index and about. When I start up
> the server, I can see my index on localhost:3000 as the default index,
> but when I try to access localhost:3000/about, it gives my a routing
> error saying "No route matches "/about" with {:method=>:get}".
> Please help
> 
> Thank you


Try this,

map.resources :controller_name, :collection => { :method_name => :get }

Thanks,
Anubhaw
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Help on Route

2010-08-10 Thread Tony Yin
hi, I'm new to rails, trying to setup a simple site, in my routes.rb I
have  map.root :controller => 'site' , and in my app/controller I have
defined site_controller.rb with action index and about. When I start up
the server, I can see my index on localhost:3000 as the default index,
but when I try to access localhost:3000/about, it gives my a routing
error saying "No route matches "/about" with {:method=>:get}".
Please help

Thank you
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Use of :include option in find query

2010-08-10 Thread Mike Disuza
Hi I have written code like this

1) Without :include
My code is :-
def user_details
@user=User.find(params[:id])
@compa...@user.company
end
Log Output:-

Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11 
10:51:34) [GET]
  Parameters: {"id"=>"2"}
  User Columns (1.0ms)   SHOW FIELDS FROM `users`
  User Load (0.4ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
  Company Load (0.4ms)   SELECT * FROM `companies` WHERE 
(`companies`.user_id = 2) LIMIT 1
Rendering template within layouts/users
Rendering users/user_details
Completed in 65ms (View: 48, DB: 2) | 200 OK 
[http://localhost/user_xml?id=2]

2) With Include:-
 def user_details
@user=User.find(params[:id], :include=>:company)
@compa...@user.company
end
Log Output:-
Processing UsersController#user_details (for 127.0.0.1 at 2010-08-11 
10:53:13) [GET]
  Parameters: {"id"=>"2"}
  User Columns (1.2ms)   SHOW FIELDS FROM `users`
  User Load (0.5ms)   SELECT * FROM `users` WHERE (`users`.`id` = 2)
  Company Load (0.3ms)   SELECT * FROM `companies` WHERE 
(`companies`.user_id = 2) LIMIT 1
Rendering template within layouts/users
Rendering users/user_details
Completed in 13ms (View: 2, DB: 2) | 200 OK 
[http://localhost/user_xml?id=2]

If you look at the both o/p there is a query on company table in both 
the cases.

What is the difference?

Thanks,
Mike
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Updating a collection in a RESTful m anner…

2010-08-10 Thread Tim Harding
@flyerhzm: I quite like the idea of updating the owner of the collection in
the case that there is one. There certainly was in my case, but it feels
weird to PUT from /school/students to /school, for example.

@chrismear: Your additional route seems cleaner than the :collection =>
{:update_all => :put} but the Wikipedia entry for REST seems to suggest that
a PUT to the collection URL should _replace_ the entire collection with
another collection so perhaps merely updating some attributes of some of the
collection breaks architectural agreement.

On 10 August 2010 09:27, flyerhzm  wrote:

> Here is an advise for "What is the Restful manner for updating a
> collection?"
>
>
> http://rails-bestpractices.com/questions/3-what-is-the-restful-manner-for-updating-a-collection
>
> On 8月9日, 下午5时52分, Chris Mear  wrote:
> > On 7 August 2010 22:07, Tim Harding  wrote:
> >
> >
> >
> > > Today I added a checkbox to each row of a table and a save button, to
> > > perform an Archive operation on N items in the table.
> >
> > > This is essentially an update of the collection.
> >
> > > My initial thought was to PUT to students_path but only GET and POST
> > > are allowed using the Rails RESTful routing.
> >
> > > I wound up adding an :collection => {:update_all => :put} to the
> > > students routing and added an appropriate controller method.
> >
> > > I'm not terribly happy with this, stylistically, though,
> > > pragmatically, it works.
> >
> > > What is the proper way to manage an update to a collection w/o having
> > > to add an addition method to my controller?
> >
> > I don't think you can avoid having an additional method in the
> > controller -- after all, the code required to update the collection is
> > going to be different from any of your other actions. But you can
> > avoid exposing the name of that new method in the URL.
> >
> > I would try manually defining a new PUT route outside of the existing
> > resource map:
> >
> > map.connect 'students', :controller => 'students', :action =>
> > 'update_collection', :conditions => {:method => :put}
> >
> > That should route correctly if you have a form with :url =>
> > students_path, :method => :put.
> >
> > There may be a cleverer/neater way to do this within the resource map
> > itself, but this at least is a good first thing to try.
> >
> > Chris
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
Tim Harding

Well Informed Ltd
Registered in England & Wales
Company number 06707839
Registered office: Suite 235, 77 Beak St, London, W1F 9DB

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Understanding this model relationship (possibly a HABTM and a belongs_to ?)

2010-08-10 Thread Rick R
I'm pretty newb and trying to get a handle on setting up a particular
relationship with my models.

For sake of this discussion (real app isn't with tools but for illustration,
using tools):

To start with (more complicated in a bit);

- A User can have multiple tools
- A single tool can only belong to one ToolGroup
- A User can belong to multiple ToolGroups

To model this relationship, I was thinking:

User
  has_many :tools
  has_and_belong_to_many :tool_groups

Tool
  has_one :tool_group
  belongs_to :user

ToolGroup
  has_and_belongs_to_many :users


So first question, is the above set up correctly?

Once the above is set up correctly, I want to have it set up where a
ToolGroup can also be 'owned' by a User. In other words, a user will set up
a ToolGroup and they are the owner, but other users can belong to this
ToolGroup. How do I model that? Do I need to set up another model that is
called "Owner" that is really a "User"? This doesn't seem right. In reality
the db table "ToolGroup" would just need an "ownerID" that would be a fk to
the User table, but I'm not sure how to model that since ToolGroup already
has a HABTM to users. Can I have a HABTM to Users and also a belongs_to
:User?

Thanks for any help

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] OT: Software fulfillment service?

2010-08-10 Thread Ralph Shnelvar
Some of us have software we'd like to sell.

I looked at
  www.swreg.org/pricing/2_9_percent.htm

and then googled the company ... many people were not happy.

Can anyone recommend a software fulfillment service or RoR code that does 
software fulfillment?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Simple File Upload to a Blob column in a SQLite DB

2010-08-10 Thread Xenio
I'm thinking maybe I should treat it as a separate form for just the
picture upload. I think the problems could be when it tries to pass
all those variables at once once I hit submit on the form.

On Aug 10, 9:41 pm, Xenio  wrote:
> So I changed my implentatio so that its set up as so:
>
> The edit view:
>
> <% form_for(@club, :html=>{:multipart=>true}) do |f| %>
>   <%= f.error_messages %>
>
>   <%= f.file_field :logo_bigg %>
>
>   
>     <%= f.label :phone %>
>     <%= f.text_field :phone %>
>   
>   
>     <%= f.label :shortdesc %>
>     <%= f.text_area :shortdesc %>
>   
>
>   
>   
>   
>     <%= f.submit 'Create' %>
>   
> <% end %>
>
> The clubs_controller:
>
> def update
>     @club = Club.find(params[:id])
>
>         #if params[:club][:logo_big] && params[:club][:logo_big].size > 0
>   #   �...@club.logo_big = params[:club][:logo_big].read
>  #   end
>         # @club.save
>
>     respond_to do |format|
>       if @club.update_attributes(params[:club])
>         flash[:notice] = 'Club was successfully updated.'
>         format.html { redirect_to(@club) }
>         format.xml  { head :ok }
>       else
>         format.html { render :action => "edit" }
>         format.xml  { render :xml => @club.errors, :status
> => :unprocessable_entity }
>       end
>     end
>   end
>
>   def image
>         data = Club.find(params[:id]).data
>         send_data data, :disposition => 'inline'
>   end
>
> The club model:
>
> class Club < ActiveRecord::Base
>   include Magick
>   belongs_to :admin
>   set_primary_key "club_id"
>
>   def logo_bigg=(input_data)
>   #  self.filename = input_data.original_filename
>  #   self.content_type = input_data.content_type.chomp
>     self.logo_big = input_data.read
>   end
>
>   def self.find_clubs
>     find(:all, :order => "name", :limit => 10)
>   end
>
>   def self.find_clubs2
>     find(:all, :order => "name", :limit => 5)
>
>   end
>
> end
>
> The issue is that it works but my rails app freezes for like 30
> seconds and I get a loud beeping from my console. When its done all I
> see if what looks like binary string data for the logging of the last
> few events.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] JOBS Ruby on Rails (RoR) technical lead needed in Minneapolis, MN long term contract

2010-08-10 Thread abork
We are looking for a senior Web App developer who can mentor other
senior (JAVA) developers on using RoR for the first time as part of an
on-going integration project.

Ruby on Rails (RoR) technical lead with extensive experience in
coaching and leading development of highly complex RoR applications.
An expert in all layers of RoR development with advanced knowledge and
ability to mentor developers.  Capable of being a leader in a highly
collaborative lab environment with the ability to guide technical and
functional discussions with the business and development teams.
Proven track record of researching and implementing RoR applications
using Agile practices.  Able to clearly communicate and lead
discussions on design patterns, technical improvements, and
implementation strategies.  Experience being a leader on a team
developing software using Test Driven Development, familiar with best
practices on refactoring, and capable of designing and articulating a
unit testing strategy for all layers of the application. Provides
direction, guidance, and mentoring on all functional and technical
areas of the system for less experienced staff.

Minimum Experience: 10+ of technical background, 6+ years directly
related web experience, 2+ years of RoR experience.  Must have been a
RoR technical lead on at least two projects.

If you’re interested please reply with a current copy of your resume
as well as your salary requirements to ab...@strategicstaff.com. Feel
free to forward this email on to anyone you know that may be looking.

Thanks in advance,
Andy Bork
Technical Recruiter
S3 / Strategic Staffing Solutions - Minneapolis
Email: ab...@strategicstaff.com
Connect to me on LinkedIn http://www.linkedin.com/in/abork

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] [Jobs] Sr. Software Engineer-Cloud Infrastructure

2010-08-10 Thread CC Pace
Hello All,
CC Pace is an IT Consulting Firm located in Fairfax, Va. We have been
in business for 30 years providing different companies with IT
solutions/SME in business and systems analysis, software development,
project management and more.

As a result of some of our long-term relationships with clients over
the years, a staff augmentation division has developed. We are
currently tier 1 vendors to several companies in the DC Metro area,
Richmond Va. and other cities across the Eastern Seaboard. Our
staffing clients look to us for assistance in finding top technical
talent for their permanent, contract and contract-to-hire
opportunities.

We are in need of a Sr. Software Engineer with Cloud Infrastructure
experience and Ruby. This is a permanent posiiton with a streaming
media client of ours located in Dulles, Va. The detailed job
description is below. If you are interested in speaking about this
opportunity further please email us and include your resume and a good
time and phone number where you can be reached.  Thank you!
---
Software Engineer (Design/Development 8-10 yrs exp)– Cloud
Infrastructure (Elasticity/Virtualization)

Looking for analytical individuals with strong computational skills to
work on cloud infrastructure projects at a premier video technologies
company.  Come join a team filled with incredibly talented individuals
which are focused on a singular goal: delivering the best video
experience to the web.  Software engineers have the satisfaction of
knowing that their efforts play a large part in the success of a small
and incredibly efficient company.  Through us you could have the
opportunity to affect people all over the world.

Required Skills:
•   provable programming prowess in Ruby (1-2 yrs) and exp with dynamic
scripting languages
•   experience working on infrastructure projects; building the
foundational pieces and middleware that run scalable applications
•   experience with Unix/Linux
•   ability to analyze, troubleshoot and design experiments to quickly
validate ideas
•   experience with a sizable source code base (1/2 milliion lines of
code)
Desirable Skills:
•   experience working on large data sets  (pedabyte of data, millions
of assets, a lot of transactions happening, 10's of thousands a
minute)
•   experience with Rails, MySQL
•   experience with Amazon Web Services (EC2, S3, SQS, SDB) Savvis Web
services good substitute
•   software engineering practices
Education Level:
•   hold or are finishing a M.S. or Ph.D. degree in computer science is
not required, but is a plus
•   degree in an analytical subject (e.g., engineering, math, statistics
or physics) and have worked on projects requiring a software
development effort of non-trivial size

Responsibilities:
Candidates will need to apply all manners of software engineering
techniques to add new features and to maintain a state of the art
infrastructure project.  Infrastructure sits at the center of the team
thus the candidate needs to have exception communication skills.  This
is a great opportunity to work on challenging and market-relevant
problems as the web-based video industry is taking off!  Candidates
should be open minded and eager to learn.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Error in Rails 3 Release notes

2010-08-10 Thread Dorian
Hello,

There is : "filter_parameter_logging is deprecated in favour of
config.filter_parameters << :password." but this don't work : and
"config.filter_parameters << :password" work, so there is an error ?

http://edgeguides.rubyonrails.org/3_0_release_notes.html#action-controller

Thanks.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Simple File Upload to a Blob column in a SQLite DB

2010-08-10 Thread Xenio
So I changed my implentatio so that its set up as so:

The edit view:

<% form_for(@club, :html=>{:multipart=>true}) do |f| %>
  <%= f.error_messages %>

  <%= f.file_field :logo_bigg %>

  
<%= f.label :phone %>
<%= f.text_field :phone %>
  
  
<%= f.label :shortdesc %>
<%= f.text_area :shortdesc %>
  

  
  
  
<%= f.submit 'Create' %>
  
<% end %>


The clubs_controller:

def update
@club = Club.find(params[:id])

#if params[:club][:logo_big] && params[:club][:logo_big].size > 0
  #@club.logo_big = params[:club][:logo_big].read
 #   end
# @club.save

respond_to do |format|
  if @club.update_attributes(params[:club])
flash[:notice] = 'Club was successfully updated.'
format.html { redirect_to(@club) }
format.xml  { head :ok }
  else
format.html { render :action => "edit" }
format.xml  { render :xml => @club.errors, :status
=> :unprocessable_entity }
  end
end
  end

  def image
data = Club.find(params[:id]).data
send_data data, :disposition => 'inline'
  end

The club model:


class Club < ActiveRecord::Base
  include Magick
  belongs_to :admin
  set_primary_key "club_id"

  def logo_bigg=(input_data)
  #  self.filename = input_data.original_filename
 #   self.content_type = input_data.content_type.chomp
self.logo_big = input_data.read
  end

  def self.find_clubs
find(:all, :order => "name", :limit => 10)
  end

  def self.find_clubs2
find(:all, :order => "name", :limit => 5)

  end


end



The issue is that it works but my rails app freezes for like 30
seconds and I get a loud beeping from my console. When its done all I
see if what looks like binary string data for the logging of the last
few events.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] convert complex SQL to ActiveRecord and Arel

2010-08-10 Thread Rob Biedenharn

On Aug 10, 2010, at 6:15 PM, jeroen wrote:

Hi,

I have a fairly complex SQL statement I'd like to convert to AREL

SELECT count(matches.id), players.*
FROM clubs
INNER JOIN players ON players.club_id = clubs.id
INNER JOIN rankings ON rankings.player_id = players.id
INNER JOIN tournaments ON rankings.tournament_id = tournaments.id
LEFT OUTER JOIN matches ON (matches.p1_id = players.id OR
matches.p2_id = players.id)
AND clubs.id = 7
AND tournaments.id = 19
GROUP BY players.id

How would I do this?


One step at a time ...


Even though you have the query Club-centric, you're asking for  
players.* so I'd start with the Player model:


Player.select('count(matches.id) as match_count, players.*')

Then you have inner joins:
  .joins([:club, { :rankings => :tournament }])

And then an outer join (this is a tricky one and depends on how you've  
defined the associations):

  .includes(:matches)

Looks like you already know the club and the tournament:
  .where(['clubs.id = ? AND tournaments.id = ?', 7, 19])

And you want the count() function to behave:
  .group('players.id')

Then ask for all of 'em:
  .all

That may not actually work, but it certainly ought to give you some  
hints.  (And there's probably other ways to get the same information,  
but you need to ask a better question to get a better answer.)


-Rob

Rob Biedenharn  
r...@agileconsultingllc.com http://AgileConsultingLLC.com/
r...@gaslightsoftware.com   http://GaslightSoftware.com/

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] convert complex SQL to ActiveRecord and Arel

2010-08-10 Thread jeroen
Hi,

I have a fairly complex SQL statement I'd like to convert to AREL

SELECT count(matches.id), players.*
FROM clubs
INNER JOIN players ON players.club_id = clubs.id
INNER JOIN rankings ON rankings.player_id = players.id
INNER JOIN tournaments ON rankings.tournament_id = tournaments.id
LEFT OUTER JOIN matches ON (matches.p1_id = players.id OR
matches.p2_id = players.id)
AND clubs.id = 7
AND tournaments.id = 19
GROUP BY players.id

How would I do this?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: habtm gets foreign key from wrong column.

2010-08-10 Thread Chris Mear
On 10 August 2010 23:02, Fritz Anderson  wrote:
> Chris Mear wrote:
>> The has_and_belongs_to_many assumes that the join table doesn't have a
>> column called 'id' -- you'll see that the SQL it generates just
>> SELECTs an 'id' column, so it's (erroneously) picking up the one from
>> the join table in your situation.
>>
>> If your join table is really a fully-fledged model of its own, then
>> you need to bring it into the association explicitly, and use the
>> :through option to connect media and tour_locations:
> ...
>
> Thanks! This was exactly what I needed to know.
>
> Further, it greatly simplified my access to subsets of the has_many
> :media relationship:
>
> has_many :images,
>            :through => :media_tour_locations,
>            :source => :medium,
>            :conditions => "media_type = 'image'",
>            :order => 'media_tour_locations.medium_sequence'
>
> ... whereby I can use aTourLocation.images and get the images back in
> the sequence specified for that relationship.
>
> I _am_ relying on the :order option to produce a correct ORDER BY
> clause. For Rails 2.3.5 and sqlite3 3.6.12, the generated SQL looks
> right, and I get the expected results.
>
> Will this hold up with different versions and back ends, or am I relying
> on an implementation detail?

Yeah, as far as I know, Rails doesn't do too much messing around with
what you pass in the :order option. So as long as you fully qualify it
by including the table name (as you have), it should be solid.

Of course, there's no substitute for writing some tests to make sure!

Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: habtm gets foreign key from wrong column.

2010-08-10 Thread Fritz Anderson
Chris Mear wrote:
> The has_and_belongs_to_many assumes that the join table doesn't have a
> column called 'id' -- you'll see that the SQL it generates just
> SELECTs an 'id' column, so it's (erroneously) picking up the one from
> the join table in your situation.
> 
> If your join table is really a fully-fledged model of its own, then
> you need to bring it into the association explicitly, and use the
> :through option to connect media and tour_locations:
...

Thanks! This was exactly what I needed to know.

Further, it greatly simplified my access to subsets of the has_many 
:media relationship:

has_many :images,
:through => :media_tour_locations,
:source => :medium,
:conditions => "media_type = 'image'",
:order => 'media_tour_locations.medium_sequence'

... whereby I can use aTourLocation.images and get the images back in 
the sequence specified for that relationship.

I _am_ relying on the :order option to produce a correct ORDER BY 
clause. For Rails 2.3.5 and sqlite3 3.6.12, the generated SQL looks 
right, and I get the expected results.

Will this hold up with different versions and back ends, or am I relying 
on an implementation detail?

— F
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Owain
This works well for me in a multi-stage environment so users can take
a screenshot of the bug and then post it to the bug tracker and I can
see straight away what version they are testing on.  First four
characters of the commit is enough in all probability.

OP:
http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/53be9640c1a16faa/aa0c607502b3a059?hl=en&lnk=gst&q=owain#aa0c607502b3a059

but in summary:


/app/config/initializers/revision.rb
filename = File.expand_path('REVISION', RAILS_ROOT)
REVISION =  File.exist?(filename) ? File.read(filename) : `cd
#{RAILS_ROOT} && git rev-parse HEAD`.strip

/app/views/layout/application.html.erb
<%- unless production? %>
  <%= "#{REVISION[0..3]} #{Time.now.to_s(:db)} "%>
<%- end -%>

/app/helpers/application_helper.rb
  def production?
  @is_production ||=(ENV['RAILS_ENV']=='production')
  end

/public/stylesheets/content.css
#revision {
color: gray;
position: absolute;
z-index: 9;
top: 10px;
left: 0px;
}

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] habtm gets foreign key from wrong column.

2010-08-10 Thread Chris Mear
On 10 August 2010 17:09, Fritz Anderson  wrote:
> I have two tables, media and tour_locations, related through a join
> table. It's not a pure join, because I need a sequence number on the
> relationship, so the join also has an id. When I access
> "aMedium.tour_locations", the reported id's for the TourLocation's are
> the id's from the join table, not the real id of the tour_locations row.
> The same for "aTourLocation.media". In the sqlite3 console, the keys and
> ids are all correct.

[snip]

> class TourLocation:
> ==
> class TourLocation < ActiveRecord::Base
>   has_and_belongs_to_many :media,
>                           :join_table => "media_tour_locations",
>                           :readonly => false
>
> class Medium:
> ==
> class Medium < ActiveRecord::Base
>  has_and_belongs_to_many :tour_locations,
>                          :join_table => "media_tour_locations",
>                          :readonly => false
>
> Schema:
> ==
>  create_table "media", :force => true do |t|
>    t.string "url",                              :null => false
>    t.string "title",       :default => ""
>    t.text   "description", :default => ""
>    t.string "media_type",  :default => "image", :null => false
>  end
>
>  create_table "media_tour_locations", :force => true do |t|
>    t.integer "medium_sequence"
>    t.integer "medium_id"
>    t.integer "tour_location_id"
>  end
>
>  create_table "tour_locations", :force => true do |t|
>    t.text     "locDescription",      :default => "Enter description",
> :null => false
>  end

The has_and_belongs_to_many assumes that the join table doesn't have a
column called 'id' -- you'll see that the SQL it generates just
SELECTs an 'id' column, so it's (erroneously) picking up the one from
the join table in your situation.

If your join table is really a fully-fledged model of its own, then
you need to bring it into the association explicitly, and use the
:through option to connect media and tour_locations:

class Medium < ActiveRecord::Base
  has_many :media_tour_locations
  has_many :tour_locations, :through => :media_tour_locations
end

class MediaTourLocation < ActiveRecord::Base
  belongs_to :medium
  belongs_to :tour_location
end

class TourLocation < ActiveRecord::Base
  has_many :media_tour_locations
  has_many :media, :through => :media_tour_locations
end

Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Validation problem

2010-08-10 Thread Ar Chron
RichardOnRails wrote:
> 
> So what do I fail to understand.  (A lot, no doubt, but how much about
> my validation of vendor selection on this form.)
> 
> Best wishes,
> Richard
> 
> On Aug 10, 3:30�pm, RichardOnRails

I think if you really want to see what Hassan is cautioning you about, 
install Firefox as a browser if you don't already have it.  Next, load 
the Firebug tool for Firefox.

Now visit your apps web page in Firefox, then activate the Firebug 
plug-in (click the little bug in the lower right corner).

Not only can you walk through your form within the Firebug window, but 
you can change attributes of that form. Find your 'form action=' 
statement, double-click the action string within the quotes and voila, 
you can alter the form target...   or anything else you want... action, 
method, values, etc.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Chris Mear
On 10 August 2010 08:39, Spong  wrote:
> So ruby seems to be installed in two place: /usr/bin/ and /opt/local/
> bin.  The former is the ruby that came with my Mac, and the latter
> from MacPorts.  Should I not use MacPorts to install/update ruby?

Well, there's nothing fundamentally wrong with having multiple Rubies
on one system. Before RVM [1] came along, I always used to compile my
own Ruby into /usr/local, and it seemed to live perfectly happy
alongside OS X's built-in Ruby.

So, the fact that MacPorts' Ruby is misbehaving in this way on your
system is strange. But unless you're particularly interested in
fathoming that problem out, the quickest fix (as Marnen and Nat have
suggested) would be to uninstall MacPorts' Ruby and use OS X's
instead, or use RVM to install your Rubies.

Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Get integers for all months between two dates

2010-08-10 Thread Michael Pavling
On 9 August 2010 18:52, Tim Booher  wrote:
>
> I have the following method which should work in Rails, but I am not
> sure if this is the best implementation. It looks a little clumsy, given
> all the good helpers in rails. Am I missing a much better way to do
> this?

As a couple of people have said, looking at this in isolation won't
allow us to easily give suggestions of better solutions, but you could
certainly tidy that method a little.

Firstly, (personal preference time!) your variable names aren't
helping your code be "self documenting". Even in such a small method,
it's frustrating to try to remember what all those single-character
variables are supposed to be doing. If they're named to refer to what
they do, they will help other people (or you when you come back to it
in a couple of months!) understand what the intention behind their
existence is.

Every time you loop round, you calculate "st.beginning_of_month" - it
would be a bit more efficient to store the value for use in the
comparison each time. You never use "st" again, so I'd just overwrite
it.

The first element you populate the array with only has "st.month", all
the others have the year too - not sure if this is a typo or intended?
Another potential typo is in the array push; you refer to a "date"
variable which I can't see set anywhere. I assume this is actually
your "d" variable?

So, if I were writing your method to be clearer, it might look like this:

  def get_months_and_years(start_date, end_date)
end_date = end_date.beginning_of_month
    return_value = [start_date.month]

working_date = start_date.beginning_of_month
    while working_date <= end_date
      return_value << [working_date.month, working_date.year]
      working_date = working_date.next_month
    end
    return return_value
  end

But
My inclination would be to be a bit more "Ruby"... assuming you want
an array of arrays of month and year for every month between two
dates:

  def get_months_and_years(start_date, end_date)
# it would be worth checking that the parameters are both valid dates/times
(start_date..end_date).collect { date| [date.month, date.year] }.uniq
  end

In that method I'm just taking the month and year for every date in
the range, and then returning unique values from the collection (so
one for each month/year combination. I've not got any time to look
into it, but I wonder if the Range.collect can step through
month-at-a-time rather than day-at-a-time...

I don't know if it's any quicker or much slower, but it's certainly
more concise, and (to my eye) a bit clearer in its intention, and
looks a lot less like PHP :-)

HTH
Michael

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Facebooker and Ruby on Rails on Facebook: Sessions problem

2010-08-10 Thread Manu Lorenzo
Hello everybody,

I am reading the book Facebook Platform Development in order to try to
code a small game for Facebook, and I have come across a "little"
problem: I am trying to insert a user every time this is logged, into a
database in my computer. I am using a couple of methods written in the
book, but there seems to be a couple of problems:

I can't seem to retrieve the session_key from Facebook using the
Facebooker helpers for RoR, and thus this value is null into the table
in my database.

Every time I reload the webpage, I can see that even though the
facebook_id is the same, the same user is added in another row to my
table in the database, even though it shouldn't; it's just supposed to
update the attribute session_key if this changes -anyway, right now this
is null.

These are the three methods I am using in order to perform all this:

def self.for(facebook_id,facebook_session=nil)
user = User.find_or_create_by_facebook_id(facebook_id)
unless facebook_session.nil?
  user.store_session(facebook_session.session_key)
end
  end

  def store_session(session_key)
if self.session_key != session_key
  update_attribute(:session_key, session_key)
end
  end

  # Re-create a Facebooker::Session object outside a request
  def facebook_session
@facebook_session ||= returning Facebooker::Session.create do
|session|
  # Facebook sessions are good for only one hour storing
  session.secure_with!(session_key,facebook_id,1.hour.from_now)
end
  end


Thanks a lot in advance to everybody!
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] ActiveRecord::UnknownAttributeError: unknown attribute:

2010-08-10 Thread Gudleik Rasch
Could be a bug or even someone trying to inject malicious javascript
code into your app.
Either case its a good practice to have these kind of scenarios
covered by tests.

You should also make sure that some fields are protected from mass-assignment.
In your hash you have is_admin => 0. If you have in your controller:
  User.create params[:user]
  # or
  @user.update_attributes params[:user]

Then anybody can create an admin user by posting is_admin=1, unless
you protect it in your model like this:

class User < ActiveRecord::Base
  attr_protected :is_admin
  # or
  attr_accessible :name, :email, :username
end

Railscasts.com has some screencasts on this topic: http://railscasts.com/tags/5

--
gudleik

On Tue, Aug 10, 2010 at 9:04 PM, Hassan Schroeder
 wrote:
> On Tue, Aug 10, 2010 at 10:21 AM, jemminger  wrote:
>
>> {"user"=>
>>  {"email_confirmation"=>"some...@example.com",
>>   "wants_new_message_notifications"=>"1",
>>   "is_admin"=>"0",
>>   "

[Rails] Re: Paperclip, id partition, and renaming images

2010-08-10 Thread Parker Selbert
Jeremy Woertink wrote:
> So some of my images look like
> 
> thumb.jpg, small.jpg, large.jpg
> 
> and some look like
> 
> thumb_23432S.jpg, small_643563456.jpg, large_2123425F.jpg
> 
> I want them all to look like the first set, so this would take care of 
> that problem?

So there is a mixture of files with the old path and files with the new 
path? That will be more complicated, you'll have to check that the old 
file exists at the old path before trying to do the move.

old_complete_path = File.join(old_path, old_file)

if File.exist?(old_complete_path)
  # Do your moving and directory making
else
  # This is 'new' content and is already in the correct place
  next
end

> 
> I also have the issue of some of the images being `original.JPG`

That is the easy part, you would change the new_file interpolation to:

new_file = "#{style}#{extension.downcase}"

- Parker

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] reload is using a cache and i dont want it to be

2010-08-10 Thread Josh
class PendingOrder < ActiveRecord::Base
  def sleep_until_processed
sleep 0.5
while !processed?
  reload
  sleep 0.25
end
  end
end

Aug 10 19:43:38 prod-app1 foo[31608]: PendingOrder Load (0.6ms)
SELECT * FROM `pending_orders` LIMIT 1
Aug 10 19:43:39 prod-app1 foo[31496]: CACHE (0.0ms)   SELECT * FROM
`pending_orders` WHERE (`pending_orders`.`id` = 221)

So the first query is legit -- but second query is cached, and so
forth.  Every subsequent query ends up being a cached value, forever.

How can I make the above method *not* look at a cache?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: How do I optimize this query?

2010-08-10 Thread Marnen Laibow-Koser
sprite wrote:
> Thanks for leading me on the right path.

Whom are you addressing?  Please quote when replying in future.

> Fixed a few errors and it
> worked great:
> 
>   def top_tippers
> sql_query = "SELECT top_tippers.total_tips AS total_tips,
>  top_tippers.client_id AS client_id,
>  users.login_slug AS login_slug,
>  users.login AS login
>  FROM (
>  SELECT SUM(tips.amount_cents) AS total_tips,
> tips.client_id AS client_id
>  FROM tips
>  WHERE tips.vendor_id = #{self.id}
>  GROUP BY tips.client_id
>  ORDER BY total_tips DESC) AS top_tippers, users
>  WHERE top_tippers.client_id  = users.id"
>  @top_tippers = User.find_by_sql(sql_query)
>   end
> 

You probably don't need to write that much SQL.  Again, see if the 
Calculations module will help.

> 
> What's the danger of interpolating the id directly? It is not passed
> in any way from the user. It is the primary_key integer ID of the
> user. 

How sure can you be that you won't get passed a bogus ID?

> How do I use placeholders when constructing the query?

Read the find_by_sql documentation.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Validation problem

2010-08-10 Thread Hassan Schroeder
On Tue, Aug 10, 2010 at 12:30 PM, RichardOnRails
 wrote:

> I don't mean to be obstinate, Hassan.  The problem is I don't see
> what's wrong with what my code presently does:
>
> My perception is that my browser renders a form with a drop-down for
> vendor selection.

So what? That's totally missing the point. Your controller can receive
a request that has *absolutely no relation* to the form you created.

You could have a select for parameter "x" offering the choices 1, 2, or
3. It's utterly trivial for anyone, with any number of tools (cf. curl, wget)
to send a request with x=4, or x=the%20horse%20you%20rode%20in%20on
or x=''.

You have *no way* to control that. You *do* have the ability to validate
your inputs, and/or deal explicitly with exceptions if those inputs aren't
what you want. But you can't make assumptions that you *know* what
those inputs are going to be when they're coming from a remote client.

-- 
Hassan Schroeder  hassan.schroe...@gmail.com
twitter: @hassan

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: (Dreaded) STI, belongs_to

2010-08-10 Thread Marnen Laibow-Koser
Gaudi Mi wrote:
> 
>> Perhaps because you should have your has_one read
>> has_one :scholarship_application !
> 
> Sorry I should have stated in the original post that I was typing 
> pseudocode here; the actual code doesn't have this mistake.

Then you *might* need a polymorphic association.  I'm not sure: I tend 
not to use STI.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Validation problem

2010-08-10 Thread RichardOnRails
Hassan,

I accidentally cause my reply to fire before I complete my statement.
Here's the continuation:

> My problem was that even though my approach failed with Rails
> displaying the params as I described the,  the crash was in am
> instance of an Expense model,  so I
I tried to get the ID of the Vendor instance referenced in the form
using the params hash.  But that hash wasn't accessible to the model
instance.  Hence the crash.

Pursuant to a previous reply to my posted question, I learned that I
could get the select-vendor's id with vendor_id in the
validate_on_create method of the Expense class instance and thus cause
an error message to be generated at the top of the form in the
browser.  Testing shows that all this works fine.

So what do I fail to understand.  (A lot, no doubt, but how much about
my validation of vendor selection on this form.)

Best wishes,
Richard

On Aug 10, 3:30 pm, RichardOnRails
 wrote:
> Hi Hassan,
>
> > > I've code exactly the logic I wanted, except for how to enforce that a
> > > vendor be selected from the drop-down before creating a new expense
> > > record.
>
> > Which you cannot do. You can "know" absolutely nothing about what
> > happens on the client side; all you can do is handle the requests that
> > you receive. Which may not include parameters that you're hoping to
> > see :-)
>
> I don't mean to be obstinate, Hassan.  The problem is I don't see
> what's wrong with what my code presently does:
>
> My perception is that my browser renders a form with a drop-down for
> vendor selection.  That drop-down is populate via a
> f.collection_select second parameter,  vendors_for_exp (with no
> argument).
>
> The latter is a method defined in app\helpers\expenses_helper.rb as
> follows:
>   def vendors_for_exp(add_null_item = true)
>     v = Vendor.find( :all, :order=>"nickname ASC")
>     if add_null_item
>       v0=Vendor.new; v0.id=0; v0.nickname = "--Select Vendor--"
>       v.insert(0, v0)
>     end
>     v
>   end
>
> The values of all the fields are are stored in params[:expenses] as a
> hash.  In particular, the vendor instance selected by the user is
> stored in  params[:expenses][:vendor].  In particular,  the id of that
> Vendor instance is accessible as params[:expenses][:vendor][:id].
> (I think strings or used instead of symbols for this stuff, but let's
> ignore that.)
>
> My problem was that even though my approach failed with Rails
> displaying the params as I described the,  the crash was in am
> instance of an Expense model,  so I
>
> On Aug 9, 11:18 am, Hassan Schroeder 
> wrote:
>
> > On Mon, Aug 9, 2010 at 8:08 AM, RichardOnRails
>
> >  wrote:
> > >> I'd suggest that it's good practice to handle any (even nil) input value
> > >> in a way appropriate to your business logic.
>
> > > I've code exactly the logic I wanted, except for how to enforce that a
> > > vendor be selected from the drop-down before creating a new expense
> > > record.
>
> > Which you cannot do. You can "know" absolutely nothing about what
> > happens on the client side; all you can do is handle the requests that
> > you receive. Which may not include parameters that you're hoping to
> > see :-)
>
> > Hence my suggestion that your code deal appropriately with those
> > situations, however unlikely you might think they are.
>
> > Good luck,
> > --
> > Hassan Schroeder  hassan.schroe...@gmail.com
> > twitter: @hassan

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Get integers for all months between two dates

2010-08-10 Thread Colin Law
On 10 August 2010 19:42, Tim Booher  wrote:
> Colin,
>
> Good point, but I am not sure of another way. I need to display
> calendars that show all events in a group. I'll look at the bigger
> picture again.

Not sure exactly what you are doing of course, but could you write
view helper code that takes the start and end dates and generates the
appropriate view stuff?

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Paperclip, id partition, and renaming images

2010-08-10 Thread Jeremy Woertink
> Of course that isn't tested, but it should give an idea. This is for the 
> filesystem and not S3, right?


Yeah, this is for the local file system.

So some of my images look like

thumb.jpg, small.jpg, large.jpg

and some look like

thumb_23432S.jpg, small_643563456.jpg, large_2123425F.jpg

I want them all to look like the first set, so this would take care of 
that problem?

I also have the issue of some of the images being `original.JPG`

I need to make sure all image file names are all downcase.

Thanks for the help!

~Jeremy
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Validation problem

2010-08-10 Thread RichardOnRails
Hi Hassan,

> > I've code exactly the logic I wanted, except for how to enforce that a
> > vendor be selected from the drop-down before creating a new expense
> > record.
>
> Which you cannot do. You can "know" absolutely nothing about what
> happens on the client side; all you can do is handle the requests that
> you receive. Which may not include parameters that you're hoping to
> see :-)

I don't mean to be obstinate, Hassan.  The problem is I don't see
what's wrong with what my code presently does:

My perception is that my browser renders a form with a drop-down for
vendor selection.  That drop-down is populate via a
f.collection_select second parameter,  vendors_for_exp (with no
argument).

The latter is a method defined in app\helpers\expenses_helper.rb as
follows:
  def vendors_for_exp(add_null_item = true)
v = Vendor.find( :all, :order=>"nickname ASC")
if add_null_item
  v0=Vendor.new; v0.id=0; v0.nickname = "--Select Vendor--"
  v.insert(0, v0)
end
v
  end

The values of all the fields are are stored in params[:expenses] as a
hash.  In particular, the vendor instance selected by the user is
stored in  params[:expenses][:vendor].  In particular,  the id of that
Vendor instance is accessible as params[:expenses][:vendor][:id].
(I think strings or used instead of symbols for this stuff, but let's
ignore that.)

My problem was that even though my approach failed with Rails
displaying the params as I described the,  the crash was in am
instance of an Expense model,  so I

On Aug 9, 11:18 am, Hassan Schroeder 
wrote:
> On Mon, Aug 9, 2010 at 8:08 AM, RichardOnRails
>
>  wrote:
> >> I'd suggest that it's good practice to handle any (even nil) input value
> >> in a way appropriate to your business logic.
>
> > I've code exactly the logic I wanted, except for how to enforce that a
> > vendor be selected from the drop-down before creating a new expense
> > record.
>
> Which you cannot do. You can "know" absolutely nothing about what
> happens on the client side; all you can do is handle the requests that
> you receive. Which may not include parameters that you're hoping to
> see :-)
>
> Hence my suggestion that your code deal appropriately with those
> situations, however unlikely you might think they are.
>
> Good luck,
> --
> Hassan Schroeder  hassan.schroe...@gmail.com
> twitter: @hassan

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Paperclip, id partition, and renaming images

2010-08-10 Thread Parker Selbert
Jeremy Woertink wrote:
> but now I have about 10,000 images that are named wrong and not showing.
> I know there is a reprocess! method in paperclip, but it doesn't seem to
> rename the images. Is there already a rake task, or something that will
> do this?
> 
> Essentially, I would like to do
> 
> MyModel.all.each { |model|
> model.image.set_all_the_styles_to_the_correct_name! }
> 
> 
> Thanks,
> ~Jeremy

You're right Jeremy, reprocess! won't manipulate the naming or 
interpolation. Whatever interpolation you have set *currently* is what 
Paperclip will apply, so it won't be able to locate the original files 
to reprocess anyhow.

I think your best bet is to work around Paperclip rather than through 
it. Take a look at how the previous url  would interpolate and compare 
that to how the current url will interpolate, then perform directory 
creation, moving, and directory removal from there. Because of the 
possible url / path permutations I doubt there are any existing rake 
tasks that will fit your particular example.

Something similar to:

Model.all.each { |model|
  model.file.styles.each do |style|
extension = File.extname(model.image.original_filename)
basename = File.basename(model.image.original_filename, extension)
old_path = File.join(RAILS_ROOT, 'assets', model.class, model.id)
old_file = "#{style}_#{basename}#{extension}"
new_path = File.join(RAILS_ROOT, 'assets', model.class, model.id, 
'image')
new_file = "#{style}#{extension}"

FileUtils.mkdir_p new_path unless File.exist?(new_path)
FileUtils.mv File.join(old_path, old_file), File.join(new_path, 
new_file)
  end
end

Of course that isn't tested, but it should give an idea. This is for the 
filesystem and not S3, right?

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: How do I optimize this query?

2010-08-10 Thread sprite
Thanks for leading me on the right path. Fixed a few errors and it
worked great:

  def top_tippers
sql_query = "SELECT top_tippers.total_tips AS total_tips,
 top_tippers.client_id AS client_id,
 users.login_slug AS login_slug,
 users.login AS login
 FROM (
 SELECT SUM(tips.amount_cents) AS total_tips,
tips.client_id AS client_id
 FROM tips
 WHERE tips.vendor_id = #{self.id}
 GROUP BY tips.client_id
 ORDER BY total_tips DESC) AS top_tippers, users
 WHERE top_tippers.client_id  = users.id"
 @top_tippers = User.find_by_sql(sql_query)
  end


What's the danger of interpolating the id directly? It is not passed
in any way from the user. It is the primary_key integer ID of the
user. How do I use placeholders when constructing the query?

On Aug 10, 12:23 pm, Marnen Laibow-Koser  wrote:
> sprite wrote:
> > Right now I am wasting a query and also losing the order of Users. Was
> > wondering what t he proper way to do this query is?
>
> > @top_tipper_ids = Tip.find_by_sql("SELECT SUM(tips.amount_cents)
> > total_tip, tips.client_id FROM tips WHERE tips.vendor_id = #...@user.id}
> > GROUP BY tips.client_id ORDER BY total_tip").collect {|e| e.client_id}
>
> > @top_tippers = User.find_all_by_id(@top_tipper_ids)
>
> > Trying to find the top tippers (Users) for a specific vendor.
>
> Will the Calculations module help you here?
>
> If not, you could add another join to get the user info in one query.
>
> And never -- but never -- interpolate the user ID in the string the way
> you're doing.  Use placeholders, or you leave yourself open for SQL
> injection.
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Faking an ActiveRecord Model

2010-08-10 Thread Robert Walker
Joao Silva wrote:
> I want to fake an ActiveRecord model like so... instead of having a Plan
> table in my database, I'd like to just have a variable somewhere
> (shallow example):
> 
>   Plans = [{ :id => 1, :price => 9.99,
>{ :id => 2, :price => 14.99,
>{ :id => 3, :price => 19.99 }]
> 
> And then I guess I'd still like to be able to associate this with my
> User model... so User.plan[:price] brings up 9.99 or whatever. User
> belongs_to :plan, so the User would have a plan_id column?
> 
> Any tips? Rails 3.

You don't have to "fake it" anymore in Rails 3. Just implement 
ActiveModel:

http://railscasts.com/episodes/219-active-model
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: (Dreaded) STI, belongs_to

2010-08-10 Thread Gaudi Mi

> Perhaps because you should have your has_one read
> has_one :scholarship_application !

Sorry I should have stated in the original post that I was typing 
pseudocode here; the actual code doesn't have this mistake.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] ActiveRecord::UnknownAttributeError: unknown attribute:

2010-08-10 Thread Hassan Schroeder
On Tue, Aug 10, 2010 at 10:21 AM, jemminger  wrote:

> {"user"=>
>  {"email_confirmation"=>"some...@example.com",
>   "wants_new_message_notifications"=>"1",
>   "is_admin"=>"0",
>   "

[Rails] Re: Validation problem

2010-08-10 Thread RichardOnRails
Hi Colin,

> Remember that all your form does is to build an http request and send
it to the server.

I didn't perceive that.  Thanks for the enlightenment.

> A hacker can build any http request he likes
without using your form, and send it to your server, with any values
in params that he fancies.

But that can be ameliorated by adding a User class with login/logout
methods with the former creating a User object.  Then I can protect
attempted use of other than a User User#login from doing so absent a
User object.  At least that's what I'm planning to implement next,
guided by Agile Web Dev w/ Rails, et al.

Sound reasonable?

On Aug 9, 11:16 am, Colin Law  wrote:
> On 9 August 2010 16:08, RichardOnRails
>
>  wrote:
> > Hi Hassan,
>
> >> > It can't be nil.  When the form is instantiated
>
> >> Assuredly, it can be -- a request can be generated without your form
> >> being involved at all.
>
> > I don't get it.  Can you point me to some tutorial that deals with
> > this issue?
>
> Remember that all your form does is to build an http request and send
> it to the server.  A hacker can build any http request he likes
> without using your form, and send it to your server, with any values
> in params that he fancies.
>
> Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Paperclip, id partition, and renaming images

2010-08-10 Thread Jeremy Woertink
I'm using paperclip in this Rails 2.3.8 project.

What I'm looking to do is rename all the images so they fit the :url =>
"/assets/:class/:id_partition/:attachment/:style.:extension" from my
model. I had about 30,000 records for this model and when changing to
start using the :id_partition, I changed

:url => "/assets/:class/:id/:attachment/:style.:extension"

to

:url => "/assets/:class/:id_partition/:style_:basename.:extension"

without thinking about what I was actually doing. I now changed it back
to

:url => "/assets/:class/:id_partition/:attachment/:style.:extension"

but now I have about 10,000 images that are named wrong and not showing.
I know there is a reprocess! method in paperclip, but it doesn't seem to
rename the images. Is there already a rake task, or something that will
do this?

Essentially, I would like to do

MyModel.all.each { |model|
model.image.set_all_the_styles_to_the_correct_name! }


Thanks,
~Jeremy
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Validation problem

2010-08-10 Thread RichardOnRails
Hi Marnen,

> a tool like curl

I found a bunch of Google hits on it.  I'll have to study them.

Thank for the tip,
Richard

On Aug 9, 11:16 am, Marnen Laibow-Koser  wrote:
> RichardOnRails wrote:
> > Hi Hassan,
>
> >> > It can't be nil. When the form is instantiated
>
> >> Assuredly, it can be -- a request can be generated without your form
> >> being involved at all.
>
> > I don't get it.  Can you point me to some tutorial that deals with
> > this issue?
>
> What do you need a tutorial for?  It's easy to use a Web browser or a
> tool like curl to send an arbitrarily crafted GET or POST request that
> never came from your form but looks as if it did.  That's just the way
> that a stateless protocol like HTTP works: each request is its own
> universe and (absent hacks like cookies) doesn't keep track of what the
> last request was.
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Parker Selbert wrote:
> Michael Schuerig wrote:
> > Capistrano already writes a REVISION file containing the commit
> > sha1. Let's assume there's a TAG file, too. Then an initializer
> > like this would do the job
> > 
> > if Rails.env.production?
> > 
> >   version = File.read('TAG').strip
> > 
> > else
> > 
> >   version = `git describe --tags --always --dirty`.chomp
> > 
> > end
> > Rails.application.config.version = version
> 
> That achieves precisely what I was saying, except uses 'TAG' instead
> of 'VERSION'. The version is simple to locate, and can be used
> anywhere it is needed.

Despite my advanced age I may still be able to learn -- and accept 
advice.

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Marnen Laibow-Koser wrote:
> Michael Schuerig wrote:
> [...]

> > Trust me, I'm not overwriting anything. Yes, I wrote so originally,
> > but that was only for easier explanation. When I had to go into
> > the details, I clarified that I'm not overwriting, but rather
> > overriding.
> 
> What's the difference?  What are you *actually* doing?  Your Cap
> recipe that you posted pretty clearly overwrites a file.  Is that
> not your actual recipe?

I would be overwriting a file if there was one to begin with. There 
isn't one.


> > Here are the desiderata:
> > 
> > * The shown version has to be current, not just the last commit.
> 
> What do you mean?  The version *is* the last commit, unless I totally
> misunderstand.
> 
> > * In production, no VERSION file is re-read for each request.

No, in development the version is *not* the last commit, but what 
happens to be in my directory. I want that to be reflected in the 
version.


> > During deployment
> > * The version is frozen to the deployed tag.
> > * No markup is written.
> > * No file is overwritten.
> > 
> > Capistrano already writes a REVISION file containing the commit
> > sha1. Let's assume there's a TAG file, too. Then an initializer
> > like this would do the job
> > 
> > if Rails.env.production?
> > 
> >   version = File.read('TAG').strip
> > 
> > else
> > 
> >   version = `git describe --tags --always --dirty`.chomp
> > 
> > end
> > Rails.application.config.version = version
> 
> This looks to me like just about exactly what I have been suggesting.
> Why do you like this and not my suggestions?  What are the
> differences as you see them?

I don't need a commit hook and I get a dirty indication in development. 
Something like "60a5c37-dirty".

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Get integers for all months between two dates

2010-08-10 Thread Tim Booher
Colin,

Good point, but I am not sure of another way. I need to display 
calendars that show all events in a group. I'll look at the bigger 
picture again.

Best,

tim

Colin Law wrote:
> On 9 August 2010 18:52, Tim Booher  wrote:
>> � � �m << [date.month, date.year]
>> � � �d = d.next_month
>> � �end
>> � �return m
>> end
> 
> No doubt there is a slicker way, but I suggest that maybe the thing
> that is a little clumsy is code that needs this functionality in the
> first place ( I mean building the array of numbers ).  Can you not
> just keep the start and end dates and determine the month and year
> values at the time you need them (if you really need them at all that
> is).
> 
> Colin

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: (Dreaded) STI, belongs_to

2010-08-10 Thread Marnen Laibow-Koser
Gaudi Mi wrote:
> Having problems with STI.  Names below have been changed to protect the
> innocent.  Imagine a system that allows someone to apply for one of two
> different types of school scholarships.  Each scholarship goes through a
> different review process, represented by a state machine (this is not a
> state machine question).  So there are two state machine classes that
> differ slightly and subclass a generic StateMachine:
> 
> class ScholarshipApplication
>   belongs_to :state_machine
> end
> 
> class StateMachine
> end
> 
> class StateA < StateMachine
>   has_one :application
> end
> 
> class StateB < StateMachine
>   has_one :application
> end
> 
> The problem is I can get a ScholarshipApplication instance to tell me
> its StateMachine, but the StateMachine can't tell me it's
> ScholarshipApplication.
[...]

Perhaps because you should have your has_one read
has_one :scholarship_application !

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] (Dreaded) STI, belongs_to

2010-08-10 Thread Gaudi Mi
Having problems with STI.  Names below have been changed to protect the
innocent.  Imagine a system that allows someone to apply for one of two
different types of school scholarships.  Each scholarship goes through a
different review process, represented by a state machine (this is not a
state machine question).  So there are two state machine classes that
differ slightly and subclass a generic StateMachine:

class ScholarshipApplication
  belongs_to :state_machine
end

class StateMachine
end

class StateA < StateMachine
  has_one :application
end

class StateB < StateMachine
  has_one :application
end

The problem is I can get a ScholarshipApplication instance to tell me
its StateMachine, but the StateMachine can't tell me it's
ScholarshipApplication.  E.g.:

app = ScholarshipApplication.create
state = StateA.create
app.state_machine = state
app.save
app.state_machine  # returns what it should
sm = app.state_machine
sm.scholarship_application # throws error: "Unknown column
scholarship_applications.state_a_id..."

So obviously I understand why this fails, since I don't have a
state_a_id column in scholarship_applications.  I just don't understand
whether what I'm doing is achievable and if so, what magic configuration
makes it all work.  E.g. should my has_one statements be in the
superclass?  Should I reverse the has_one and belongs_to?  Something
else?

Thanks!
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Dynamically creating the html for forms created by user in application.

2010-08-10 Thread Nat Budin
On Aug 10, 2:30 am, Rtdp  wrote:
> hello,
> In my rails application, a user creates a form by selecting the type
> of the data i.e.(string, integer, text) and he then gives input filed
> name for it.
> i.e. if user wants Name as capition, txtname as input field name and
> string as database field type the form will generated as -
> 
> Name: 
> 
> 
>
> So how can create this html from this user given information. Is there
> a plugin for this work ?

This is a pretty common use case in lots of applications, and
depending on what sorts of customization you want to allow your users,
you can get quite complex with it if you like.  But in the simple
case, you basically want four model classes, divided roughly into a
set of two for the form creators, and two for the users filling out
the forms.  Here's an example using your terminology:

UserForm is a form created by a user
FormField is a field on a UserForm, which contains a caption, a type,
and a txtname
UserForm has_many :form_fields

...and, parallel to these, for the users filling out the forms...

FormReply is one instance of a UserForm that's been filled out
ReplyValue is the answer the user gave to a particular FormField
FormReply has_many :reply_values, and belongs_to :user_form
(and UserForm has_many :form_replies)

When generating the HTML for this kind of thing, the key concept to
keep in mind is that what the user's actually doing is _creating a
FormReply_.  Thus, the ERB template might look like this:

<%= form_for(@form_reply) do |f| %>
  <%= fields_for :reply_values do |value_fields| %>
<%= value_fields.text_field :value %>
  <% end %>
  <%= f.submit_tag %>
<% end %>

The above template assumes you've set FormReply to accept nested
attributes for reply_values, and that you're going to populate a blank
set of them in the controller action.

Of course, this is only one way to do it, and I'm sure others have
differing opinions on approaches... :)

Nat

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Faking an ActiveRecord Model

2010-08-10 Thread Robby Russell
On Tue, Aug 10, 2010 at 8:51 AM, Joao Silva  wrote:
> I want to fake an ActiveRecord model like so... instead of having a Plan
> table in my database, I'd like to just have a variable somewhere
> (shallow example):
>
>  Plans = [{ :id => 1, :price => 9.99,
>           { :id => 2, :price => 14.99,
>           { :id => 3, :price => 19.99 }]
>
> And then I guess I'd still like to be able to associate this with my
> User model... so User.plan[:price] brings up 9.99 or whatever. User
> belongs_to :plan, so the User would have a plan_id column?
>
> Any tips? Rails 3.
>

I hate to ask the obvious question here... but why not just have a
regular model with a table behind it? What problem are you solving
here? What problems are you introducing? Just want to make sure you're
factoring the tradeoffs here...

Cheers,
Robby

-- 
Robby Russell
Chief Evangelist, Partner

PLANET ARGON, LLC
Web Design and Development with Ruby on Rails

http://planetargon.com/

+1 408 372 7466
+1 815 642 4068 [fax]

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] filtering results based on multiple criteria

2010-08-10 Thread richardsugg
What's the paradigm for providing a set of filters for search
results?

Here's my example:  I have a list of projects, and projects can be
filtered by manager, status (open, closed, in progress), start date,
etc.  The filter settings are stored in the database using the
preferences plugin, which works very nicely.  However, my code is
ugly, and I can't detect when a filter has be unset, which makes me
think there is a better way.

ProjectsController:

# the if statement always returns true even if show_closed_projects is
unchecked
def index
  @projects = Projects.all
  if defined? params[:show_closed_projects] &&
params[:show_closed_projects] == 'on'
current_user.write_preference(:show_closed_projects, true)
@projects = @projects.closed # this is a named scope
  else
current_user.wrirte_preference(:show_closed_projects, false)
  end
end

views/projects/index.html.erb
# this works -- if the preference is set, the checkbox is checked,
otherwise, it's not checked.

  

  project filter options
  

  

>
Show closed projects?
  

  


  <%= submit_tag "save filters" %>
  <%= link_to "cancel" %>

  


...projects listed here...

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Parker Selbert
Michael Schuerig wrote:
> Capistrano already writes a REVISION file containing the commit sha1.
> Let's assume there's a TAG file, too. Then an initializer like this
> would do the job
> 
> if Rails.env.production?
>   version = File.read('TAG').strip
> else
>   version = `git describe --tags --always --dirty`.chomp
> end
> Rails.application.config.version = version

That achieves precisely what I was saying, except uses 'TAG' instead of
'VERSION'. The version is simple to locate, and can be used anywhere it
is needed.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] ActiveRecord::UnknownAttributeError: unknown attribute:

2010-08-10 Thread jemminger
Has anyone seen this happening to their apps?

I'm starting to get errors like this come across from one of my apps:

  ActiveRecord::UnknownAttributeError: unknown attribute: 

[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Marnen Laibow-Koser
Michael Schuerig wrote:
[...]
>> If it's not hidden, the user can actually *see* the build number
>> rather than having to send you the HTML source.  (This is the
>> approach we use here at work.)
> 
> No way, I'm constrained by the visual design people.

They won't let you put it somewhere inconspicuous?  Oy.

> 
>> Besides,  is meant for the version of the
>> *document*, not the version of the *application* that built it, isn't
>> it?
> 
> It's no big deal changing "version" to "app-version".

True.

> 
>> > I may need to mention that I'm not
>> > actually overwriting a file. The partial containing the explicit
>> > call to git is contained in an engine common to several
>> > applications. The partial I write that's containing the deployed
>> > version is in the app itself and therefore earlier in the path.
>> 
>> But you *are* overwriting a file.  Your initial post with your Cap
>> recipe says that you're doing just that.
> 
> Trust me, I'm not overwriting anything. Yes, I wrote so originally, but
> that was only for easier explanation. When I had to go into the details,
> I clarified that I'm not overwriting, but rather overriding.

What's the difference?  What are you *actually* doing?  Your Cap recipe 
that you posted pretty clearly overwrites a file.  Is that not your 
actual recipe?

>> In other words, the same code that now writes > content="#{tag}"> in your partial should probably be changed to write
>> VERSION=#{tag} in some initializer file.  Then the partial can just
>> read VERSION -- and so can anything else that needs to know the
>> build number.
> 
> I don't like that. 

Why not?

> I need to write that file in my development
> environment, possibly using a git post-commit hook.

Why?  It should probably be written in the production environment as 
part of the post-deploy process.

[...]
> Here are the desiderata:
> 
> * The shown version has to be current, not just the last commit.

What do you mean?  The version *is* the last commit, unless I totally 
misunderstand.

> * In production, no VERSION file is re-read for each request.

Right now, you're potentially rereading your partial for each request. 
A VERSION initializer such as I have suggested would load the constant 
in memory once at app startup and never read it again.

> 
> During deployment
> * The version is frozen to the deployed tag.
> * No markup is written.
> * No file is overwritten.
> 
> Capistrano already writes a REVISION file containing the commit sha1.
> Let's assume there's a TAG file, too. Then an initializer like this
> would do the job
> 
> if Rails.env.production?
>   version = File.read('TAG').strip
> else
>   version = `git describe --tags --always --dirty`.chomp
> end
> Rails.application.config.version = version

This looks to me like just about exactly what I have been suggesting. 
Why do you like this and not my suggestions?  What are the differences 
as you see them?

> 
> 
> Michael
> 
> --
> Michael Schuerig
> mailto:mich...@schuerig.de
> http://www.schuerig.de/michael/

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Marnen Laibow-Koser wrote:
> Michael Schuerig wrote:
> > On Tuesday 10 August 2010, Marnen Laibow-Koser wrote:
> >> Then, instead of a meta tag, why not just put it in a hidden (or
> >> smallish) div in the HTML?
> > 
> > Why? I don't see what I would gain.
> 
> If it's not hidden, the user can actually *see* the build number
> rather than having to send you the HTML source.  (This is the
> approach we use here at work.)

No way, I'm constrained by the visual design people.

> Besides,  is meant for the version of the
> *document*, not the version of the *application* that built it, isn't
> it?

It's no big deal changing "version" to "app-version".

> > I may need to mention that I'm not
> > actually overwriting a file. The partial containing the explicit
> > call to git is contained in an engine common to several
> > applications. The partial I write that's containing the deployed
> > version is in the app itself and therefore earlier in the path.
> 
> But you *are* overwriting a file.  Your initial post with your Cap
> recipe says that you're doing just that.

Trust me, I'm not overwriting anything. Yes, I wrote so originally, but 
that was only for easier explanation. When I had to go into the details, 
I clarified that I'm not overwriting, but rather overriding.

> >> And I think Parker may have the right idea.  It seems reasonable
> >> to read this from a VERSION file that's updated by Git or Cap.
> > 
> > That doesn't explain why that approach is better than what I'm
> > currently doing. Yes, it does seem reasonable, but is my current
> > approach unreasonable?
> 
> I think it is.  It seems extremely hackish.  The build number is an
> application-wide constant, so it should be defined as a Ruby constant
> (so that the app can be aware of it) instead of just hacked into an
> ERb partial.
> 
> In other words, the same code that now writes  content="#{tag}"> in your partial should probably be changed to write
> VERSION=#{tag} in some initializer file.  Then the partial can just
> read VERSION -- and so can anything else that needs to know the
> build number.

I don't like that. I need to write that file in my development 
environment, possibly using a git post-commit hook. When there are 
uncomitted changes, the version I get is outdated. Using

  `git describe --tags --always --dirty`

in a partial, I get an indication that I'm looking at a page generated 
from an uncommitted version.

Here are the desiderata:

* The shown version has to be current, not just the last commit.
* In production, no VERSION file is re-read for each request.

During deployment
* The version is frozen to the deployed tag.
* No markup is written.
* No file is overwritten.

Capistrano already writes a REVISION file containing the commit sha1. 
Let's assume there's a TAG file, too. Then an initializer like this 
would do the job

if Rails.env.production?
  version = File.read('TAG').strip
else
  version = `git describe --tags --always --dirty`.chomp
end
Rails.application.config.version = version


Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: How do I optimize this query?

2010-08-10 Thread Marnen Laibow-Koser
sprite wrote:
> Right now I am wasting a query and also losing the order of Users. Was
> wondering what t he proper way to do this query is?
> 
> @top_tipper_ids = Tip.find_by_sql("SELECT SUM(tips.amount_cents)
> total_tip, tips.client_id FROM tips WHERE tips.vendor_id = #...@user.id}
> GROUP BY tips.client_id ORDER BY total_tip").collect {|e| e.client_id}
> 
> @top_tippers = User.find_all_by_id(@top_tipper_ids)
> 
> Trying to find the top tippers (Users) for a specific vendor.

Will the Calculations module help you here?

If not, you could add another join to get the user info in one query.

And never -- but never -- interpolate the user ID in the string the way 
you're doing.  Use placeholders, or you leave yourself open for SQL 
injection.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Marnen Laibow-Koser
One more thing...

Michael Schuerig wrote:
> On Tuesday 10 August 2010, Parker Selbert wrote:
[...]
>> 3. Can't ever have the incorrect tag in your layout
> 
> That's the same for both approaches, isn't it? When I deploy a tag, that
> tag is used to access the git repo and it is written to the partial.

I think Parker was referring to the fact that you can't ever have the 
wrong *HTML* tag, not Git tag, if you don't have your recipe messing 
with your layout.

> 
> Michael
> 
> --
> Michael Schuerig
> mailto:mich...@schuerig.de
> http://www.schuerig.de/michael/

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Marnen Laibow-Koser
Nat Budin wrote:
> On Aug 10, 11:28�am, Marnen Laibow-Koser  wrote:
>> Frederick Cheung wrote:
>> > As long as the bug in bigdecimal doesn't bother you :-)
>>
>> Can't say I've run into that. �Info?
>>
>> (For the record, the only projects on which I've been using BigDecimal
>> at all have been using Rubinius or JRuby, not MRI.)
> 
> I hadn't either, but this article gives the details:
> http://www.abletech.co.nz/2010/03/osx-10-6-3-installs-new-ruby-with-faulty-bigdecimal/
> 
> From the article:
> 
> BigDecimal.new("3.0009").to_f
> => 3.9
> 

Ouch!  I think I'm using patchlevel 287, which would imply that a later 
upgrade to Snow Leopard fixed the patch, but I'm not at that computer 
right now to check.  If I *am* using the faulty version, that implies 
that I finally have a use for RVM.

> Nat

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Marnen Laibow-Koser
Parker Selbert wrote:
[...]
> Really the idea was that you would remove writing markup as part of your 
> deploy recipe,

I agree with this too.  If your deploy recipe is writing markup, 
something is very, very wrong.  If you just set a constant VERSION with 
your deploy recipe, then you won't have your deploy recipe reaching so 
far into your app code.

In other words: a properly written deploy recipe can set configuration 
values, but should not otherwise change your app.  That implies that it 
can touch initializers and config files, but should not touch anything 
in Rails.root/app .  Otherwise, you're setting yourself up for weird 
maintenance problems, I think.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Marnen Laibow-Koser
Michael Schuerig wrote:
> On Tuesday 10 August 2010, Marnen Laibow-Koser wrote:
>> Then, instead of a meta tag, why not just put it in a hidden (or
>> smallish) div in the HTML?
> 
> Why? I don't see what I would gain.

If it's not hidden, the user can actually *see* the build number rather 
than having to send you the HTML source.  (This is the approach we use 
here at work.)

Besides,  is meant for the version of the 
*document*, not the version of the *application* that built it, isn't 
it?

> I may need to mention that I'm not
> actually overwriting a file. The partial containing the explicit call to
> git is contained in an engine common to several applications. The
> partial I write that's containing the deployed version is in the app
> itself and therefore earlier in the path.

But you *are* overwriting a file.  Your initial post with your Cap 
recipe says that you're doing just that.

> 
>> And I think Parker may have the right idea.  It seems reasonable to
>> read this from a VERSION file that's updated by Git or Cap.
> 
> That doesn't explain why that approach is better than what I'm currently
> doing. Yes, it does seem reasonable, but is my current approach
> unreasonable?
> 

I think it is.  It seems extremely hackish.  The build number is an 
application-wide constant, so it should be defined as a Ruby constant 
(so that the app can be aware of it) instead of just hacked into an ERb 
partial.

In other words, the same code that now writes  in your partial should probably be changed to write 
VERSION=#{tag} in some initializer file.  Then the partial can just read 
VERSION -- and so can anything else that needs to know the build number.

> Michael
> 
> --
> Michael Schuerig
> mailto:mich...@schuerig.de
> http://www.schuerig.de/michael/

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] habtm gets foreign key from wrong column.

2010-08-10 Thread Fritz Anderson
I have two tables, media and tour_locations, related through a join
table. It's not a pure join, because I need a sequence number on the
relationship, so the join also has an id. When I access
"aMedium.tour_locations", the reported id's for the TourLocation's are
the id's from the join table, not the real id of the tour_locations row.
The same for "aTourLocation.media". In the sqlite3 console, the keys and
ids are all correct.

How can I fix this?

Ruby 1.8.7, Rails 2.3.5, sqlite3 3.6.12

Here is an abbreviated console dialog. MediaTourLocation(25) relates
Medium(16) to TourLocation(6).

==
>> tl = TourLocation.find(6)
>> tl.media
[... #http://www.li...> ...]
>> MediaTourLocation.find_all_by_tour_location_id(6)
[... # ...]
>> med = Medium.find(16)
>> med.tour_locations
[#]
==

The Medium and the TourLocation report each other as id: 25. That's
wrong; neither table has a row with that id. My web pages crash.

The habtm declarations and the schema appear at the end of this message.
You'll see I've been thrashing

class TourLocation:
==
class TourLocation < ActiveRecord::Base
   has_and_belongs_to_many :media,
   :join_table => "media_tour_locations",
   :readonly => false

class Medium:
==
class Medium < ActiveRecord::Base
  has_and_belongs_to_many :tour_locations,
  :join_table => "media_tour_locations",
  :readonly => false

Schema:
==
  create_table "media", :force => true do |t|
t.string "url",  :null => false
t.string "title",   :default => ""
t.text   "description", :default => ""
t.string "media_type",  :default => "image", :null => false
  end

  create_table "media_tour_locations", :force => true do |t|
t.integer "medium_sequence"
t.integer "medium_id"
t.integer "tour_location_id"
  end

  create_table "tour_locations", :force => true do |t|
t.text "locDescription",  :default => "Enter description",
:null => false
  end
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Parker Selbert wrote:
> Michael Schuerig wrote:
> >> I don't see where security would be an issue here, but reusability
> >> may be. A more generic "VERSION" file that can be loaded and read
> >> from would be available anywhere in your application, and could be
> >> simpler to maintain. You could do it as a plaintext file that just
> >> reads '1.1.42', or namespace it as MyApp::VERSION etc.
> > 
> > I didn't explain why I want this version number to begin with. I
> > don't need the version anywhere in the app. The whole point is to
> > identify the version of the app that has generated a page. So, if
> > I get a bug report from a tester or user, I can tell them to
> > attach the offending page to the bug report and from that I can
> > find out what version they were using.
> > 
> > Michael
> 
> Really the idea was that you would remove writing markup as part of
> your deploy recipe, and more importantly than that you'd automate
> syncing the VERSION with git.
> 
> With this method:
> 
> 1. You have less to remember

I don't follow. What do I have to remember with my current method?

> 2. A more orthogonal use of your deploy and layout

There I don't feel any guilt.

> 3. Can't ever have the incorrect tag in your layout

That's the same for both approaches, isn't it? When I deploy a tag, that 
tag is used to access the git repo and it is written to the partial.

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Faking an ActiveRecord Model

2010-08-10 Thread Joao Silva
I want to fake an ActiveRecord model like so... instead of having a Plan
table in my database, I'd like to just have a variable somewhere
(shallow example):

  Plans = [{ :id => 1, :price => 9.99,
   { :id => 2, :price => 14.99,
   { :id => 3, :price => 19.99 }]

And then I guess I'd still like to be able to associate this with my
User model... so User.plan[:price] brings up 9.99 or whatever. User
belongs_to :plan, so the User would have a plan_id column?

Any tips? Rails 3.

Thanks!
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Marnen Laibow-Koser wrote:
> Michael Schuerig wrote:
> [...]
> 
> > I didn't explain why I want this version number to begin with. I
> > don't need the version anywhere in the app. The whole point is to
> > identify the version of the app that has generated a page. So, if
> > I get a bug report from a tester or user, I can tell them to
> > attach the offending page to the bug report and from that I can
> > find out what version they were using.
> 
> Then, instead of a meta tag, why not just put it in a hidden (or
> smallish) div in the HTML?

Why? I don't see what I would gain. I may need to mention that I'm not 
actually overwriting a file. The partial containing the explicit call to 
git is contained in an engine common to several applications. The 
partial I write that's containing the deployed version is in the app 
itself and therefore earlier in the path.

> And I think Parker may have the right idea.  It seems reasonable to
> read this from a VERSION file that's updated by Git or Cap.

That doesn't explain why that approach is better than what I'm currently 
doing. Yes, it does seem reasonable, but is my current approach 
unreasonable?

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Nat Budin
On Aug 10, 11:28 am, Marnen Laibow-Koser  wrote:
> Frederick Cheung wrote:
> > As long as the bug in bigdecimal doesn't bother you :-)
>
> Can't say I've run into that.  Info?
>
> (For the record, the only projects on which I've been using BigDecimal
> at all have been using Rubinius or JRuby, not MRI.)

I hadn't either, but this article gives the details:
http://www.abletech.co.nz/2010/03/osx-10-6-3-installs-new-ruby-with-faulty-bigdecimal/

>From the article:

BigDecimal.new("3.0009").to_f
=> 3.9

Nat

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] How do I optimize this query?

2010-08-10 Thread Edmond Kachale
Sprite,

I would propose a custom view that exploits SQL powers. I do not know how
much info you would like to syphon from the user model. Here is what I think
you can do:

*Code (In User model):

*
sql_query = "SELECT total_tippers.total_tips AS total_tips,
  total_tippers.client_id AS client_id
  users.first_name AS first_name,
  users.last_name AS surname,
  users.add_all_other_fields_you_require AS each_required_field
FROM (
SELECT SUM(tips.amount_cents)AS total_tips, tips.client_id AS client_id
FROM tips
WHERE tips.vendor_id = #...@user.id}
GROUP BY tips.client_id
ORDER BY total_tip ) AS top_tippers, users
WHERE top_tippers.client_id  = users.id"

@top_tippers = self.find_by_sql(sql_query)

*Expected/Sample Output (tabulated for the sake of crarity):*

*total_tips  client_id first_name  surname each_required_field*
  25   4 Aake   Gregertsen  data_1
  23   1 Edmond   Kachale  data_1

*Points to note:*

   - I chose to use *User* model. This is to reflect that the top_tipper is
   a user not the tip itself. (for *sense* and *readability*'s sake). In
   addition, I think it's a *user* who *has* (*many*) *tips* and not the
   other way round ([?]).
   - If you only want to use the user (without making use of the other data
   e.g. total_tips, client_id), as depicted by the "*.collect*" operation on
   your Tip model, then you can just scrap off the fields in the outer query so
   that it appears like this: sql_query = "SELECT * FROM (
   SELECT SUM(tips.amount_cents)AS total_tips, tips.client_id AS
   client_id
   FROM tips
   WHERE tips.vendor_id = #...@user.id}
   GROUP BY tips.client_id
   ORDER BY total_tip ) AS top_tippers, users
   WHERE top_tippers.client_id  = users.id" . But be ready to hassle a bit
   in order to find the fields you want. May be you can use script/console to
   figure out, though most geeks discourage testing codes from script/console.
   - *Caution*: I haven't tested the code; *expect a bug if you use as it is
   *. You may need to customize it to fit your models and tables details.
   (nice one, isn't it? [?][?])

Sorry for *my long folk-tale*. [?][?]

Regards,

---
Edmond
Software Developer | Baobab Health Trust (http://www.baobabhealth.org/) |Malawi

Cell: +265 999 465 137 | +265 881 234 717
Skype: ceekays

*"A more radical argument for [statistical Natural Language Processing] is
that human cognition is probabilistic and that language must therefore be
probabilistic too since it is an integral part of cognition." -- Chris
Manning (1999)*, *Foundations of Statistical Natural Language Processing*.



2010/8/10 sprite 

> Right now I am wasting a query and also losing the order of Users. Was
> wondering what t he proper way to do this query is?
>
> @top_tipper_ids = Tip.find_by_sql("SELECT SUM(tips.amount_cents)
> total_tip, tips.client_id FROM tips WHERE tips.vendor_id = #...@user.id}
> GROUP BY tips.client_id ORDER BY total_tip").collect {|e| e.client_id}
>
> @top_tippers = User.find_all_by_id(@top_tipper_ids)
>
> Trying to find the top tippers (Users) for a specific vendor.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to
> rubyonrails-talk+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

<><<360.gif>>

[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Marnen Laibow-Koser
Frederick Cheung wrote:
> On 10 Aug, 15:41, Marnen Laibow-Koser  wrote:
>> Some people like to install through Ports or Fink or build it themselves
>> regardless, but I think that's just a waste of time and disk space.
> 
> As long as the bug in bigdecimal doesn't bother you :-)

Can't say I've run into that.  Info?

(For the record, the only projects on which I've been using BigDecimal 
at all have been using Rubinius or JRuby, not MRI.)

> 
> Fred

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Frederick Cheung


On 10 Aug, 15:41, Marnen Laibow-Koser  wrote:
> Spong wrote:
>
> [...]
>
> > So ruby seems to be installed in two place: /usr/bin/ and /opt/local/
> > bin.  The former is the ruby that came with my Mac, and the latter
> > from MacPorts.  Should I not use MacPorts to install/update ruby?
>
> The Ruby that comes with Leopard is perfectly adequate (it's what I'm
> using for development), unless you specifically want a newer version.
> Some people like to install through Ports or Fink or build it themselves
> regardless, but I think that's just a waste of time and disk space.

As long as the bug in bigdecimal doesn't bother you :-)

Fred
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Nat Budin
What Marnen said.  Also, if you want to test stuff with multiple
versions of Ruby, rvm is an easy way to automatically install and
isolate different versions of Ruby on the same machine.

http://rvm.beginrescueend.com/

Nat

On Aug 10, 10:41 am, Marnen Laibow-Koser  wrote:
> The Ruby that comes with Leopard is perfectly adequate (it's what I'm
> using for development), unless you specifically want a newer version.
> Some people like to install through Ports or Fink or build it themselves
> regardless, but I think that's just a waste of time and disk space.
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> mar...@marnen.org
> --
> Posted viahttp://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Rails best practice to check an object ’s existence before displaying an attribute in a layout

2010-08-10 Thread Dave Aronson
On Mon, Aug 9, 2010 at 19:23, wtb  wrote:

> <% if post.has_tag != nil %>
...
> def has_tag
>  !self.tags.empty?
> end

false is not the same as nil.  You've been hacking too much LISP.  :-)
 Dump the "!= nil", leaving simply "if post.has_tag".

-Dave

-- 
Specialization is for insects. -RAH  | Have Pun, Will Babble! -me
Programming Blog: http://codosaur.us | Work: http://davearonson.com
Leadership Blog:  http://dare2xl.com | Play: http://davearonson.net
* * * * * WATCH THIS SPACE * * * * * | Ruby: http://mars.groupsite.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Parker Selbert
Michael Schuerig wrote:
>> I don't see where security would be an issue here, but reusability
>> may be. A more generic "VERSION" file that can be loaded and read
>> from would be available anywhere in your application, and could be
>> simpler to maintain. You could do it as a plaintext file that just
>> reads '1.1.42', or namespace it as MyApp::VERSION etc.
> 
> I didn't explain why I want this version number to begin with. I don't
> need the version anywhere in the app. The whole point is to identify the
> version of the app that has generated a page. So, if I get a bug report
> from a tester or user, I can tell them to attach the offending page to
> the bug report and from that I can find out what version they were
> using.
> 
> Michael

Really the idea was that you would remove writing markup as part of your 
deploy recipe, and more importantly than that you'd automate syncing the 
VERSION with git.

With this method:

1. You have less to remember
2. A more orthogonal use of your deploy and layout
3. Can't ever have the incorrect tag in your layout

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Marnen Laibow-Koser
Spong wrote:
[...]
> So ruby seems to be installed in two place: /usr/bin/ and /opt/local/
> bin.  The former is the ruby that came with my Mac, and the latter
> from MacPorts.  Should I not use MacPorts to install/update ruby?

The Ruby that comes with Leopard is perfectly adequate (it's what I'm 
using for development), unless you specifically want a newer version. 
Some people like to install through Ports or Fink or build it themselves 
regardless, but I think that's just a waste of time and disk space.

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Marnen Laibow-Koser
Michael Schuerig wrote:
[...]
> I didn't explain why I want this version number to begin with. I don't
> need the version anywhere in the app. The whole point is to identify the
> version of the app that has generated a page. So, if I get a bug report
> from a tester or user, I can tell them to attach the offending page to
> the bug report and from that I can find out what version they were
> using.

Then, instead of a meta tag, why not just put it in a hidden (or 
smallish) div in the HTML?

And I think Parker may have the right idea.  It seems reasonable to read 
this from a VERSION file that's updated by Git or Cap.

> 
> Michael

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig
On Tuesday 10 August 2010, Parker Selbert wrote:
> Michael Schuerig wrote:
> > I'd like to be able to see from generated pages which version of
> > the app has generated it. As we're using git and always deploy a
> > specific tag, having that tag in the HTML head as a meta tag would
> > be suitable.
> > 
> > My current idea goes like this. The layout includes a partial that
> > looks like this
> > 
> >>   
> >content="<%= `git describe --tags --always --dirty`.chomp %>">
> > 
> > When deployed, this file is overwritten with a static one referring
> > to the deployed git tag
> > 
> >   
> >
[capistrano recipe for writing the version snipped]


> I don't see where security would be an issue here, but reusability
> may be. A more generic "VERSION" file that can be loaded and read
> from would be available anywhere in your application, and could be
> simpler to maintain. You could do it as a plaintext file that just
> reads '1.1.42', or namespace it as MyApp::VERSION etc.

I didn't explain why I want this version number to begin with. I don't 
need the version anywhere in the app. The whole point is to identify the 
version of the app that has generated a page. So, if I get a bug report 
from a tester or user, I can tell them to attach the offending page to 
the bug report and from that I can find out what version they were 
using.

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Parker Selbert
Michael Schuerig wrote:
> I'd like to be able to see from generated pages which version of the app
> has generated it. As we're using git and always deploy a specific tag,
> having that tag in the HTML head as a meta tag would be suitable.
> 
> My current idea goes like this. The layout includes a partial that looks
> like this
> 
>   content="<%= `git describe --tags --always --dirty`.chomp %>">
> 
> When deployed, this file is overwritten with a static one referring to
> the deployed git tag
> 
>   
> 
> Then, in the capistrano recipe,
> 
>   after "deploy:update_code", "deploy:freeze_version_partial"
> 
>   namespace :deploy do
> task :freeze_version_partial do
>   put %{\n},
> File.join(current_release,
>  'app/views/layouts/_version.html.erb'),
>:roles => :web
> end
>   end
> 
> Deployment then requires a tag to be given
> 
>   $ cap -S tag=v1.1.42 deploy
> 
> 
> Are there reasons not to do this or not to do it this way? I don't think
> there is a security problem of exposing to many details about the app as
> it is only for internal use.
> 
> Michael
> 
> --
> Michael Schuerig
> mailto:mich...@schuerig.de
> http://www.schuerig.de/michael/

I don't see where security would be an issue here, but reusability may 
be. A more generic "VERSION" file that can be loaded and read from would 
be available anywhere in your application, and could be simpler to 
maintain. You could do it as a plaintext file that just reads '1.1.42', 
or namespace it as MyApp::VERSION etc.

You could add a post-commit hook that would write to the VERSION file, 
make sure that you bump the version when you tag, or put your git call 
right into the file. Automating this would prevent your deploy from 
failing if you forget to state the tag as well.

Of course you don't have to do any of these things, just some ways I see 
to remove human error and streamline things for you guys.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Use of :include option in find query

2010-08-10 Thread Colin Law
On 10 August 2010 13:44, Mike Disuza  wrote:
>
>
> Hi,
> I have a Person model and Company model like as follows:-
>
> Person.rb
>
> class Person    has_one :company
> end
>
> Company.rb
> class Company < ActiveRecord::Base
> end
>
> I have a function
> def person_details
> �...@person=person.find(params[:id, :include=> :company)
> end
>
> person_details.html.erb
> <%...@person.name%> : <%...@person.company.name%>
>
> I read that if you use the :include option then it reduces your number
> of queries.
> Means, whenever it is firing a query to find person same time it eager
> loads the company association.
>
> I am confused that what exactly it does? Is it load the company object
> in memory? and instead of going to database it takes it from memory.

Write some code that uses your find and then accesses person.company
and look in the log to see the queries being used.  Repeat without the
:include and you will see the difference.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Simple File Upload to a Blob column in a SQLite DB

2010-08-10 Thread Colin Law
On 10 August 2010 13:18, Xenio  wrote:
> Hey Chris,
>
> I think I sent a reply to just you by mistake. Is there anyway you can
> post it here? Apparently I do not get copies of messages sent to
> author only in google groups.

It will be in your Sent Items or whatever it is called in your mailer.
 Just go there and forward it to the list.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Deployment: adding git tag as HTML meta tag

2010-08-10 Thread Michael Schuerig

I'd like to be able to see from generated pages which version of the app 
has generated it. As we're using git and always deploy a specific tag, 
having that tag in the HTML head as a meta tag would be suitable.

My current idea goes like this. The layout includes a partial that looks 
like this

  

When deployed, this file is overwritten with a static one referring to 
the deployed git tag

  

Then, in the capistrano recipe,

  after "deploy:update_code", "deploy:freeze_version_partial"

  namespace :deploy do
task :freeze_version_partial do
  put %{\n},
File.join(current_release,
 'app/views/layouts/_version.html.erb'),
   :roles => :web
end
  end

Deployment then requires a tag to be given

  $ cap -S tag=v1.1.42 deploy


Are there reasons not to do this or not to do it this way? I don't think 
there is a security problem of exposing to many details about the app as 
it is only for internal use.

Michael

-- 
Michael Schuerig
mailto:mich...@schuerig.de
http://www.schuerig.de/michael/

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] install_theme

2010-08-10 Thread Abder-Rahman Ali
In following this tutorial in the "install_theme" plugin:
http://drnicwilliams.com/2009/10/06/install-any-html-themetemplate-into-your-rails-app/

When I run the following: (Provided I'm using Rails3.0.0.rc)

$ install_theme /auth /refreshed/refreshed content_path

auth: path to application
/refreshed/refreshed: path to template

I get the following:

http://pastie.org/private/ew80kn7pcc9oywwynz5sog

Why is that?

Thanks.
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Routing, need fast help

2010-08-10 Thread Ainar Abramovich
BTW does anyone know place where to look for templates?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Use of :include option in find query

2010-08-10 Thread Mike Disuza


Hi,
I have a Person model and Company model like as follows:-

Person.rb

class Person  :company)
end

person_details.html.erb
<%...@person.name%> : <%...@person.company.name%>

I read that if you use the :include option then it reduces your number
of queries.
Means, whenever it is firing a query to find person same time it eager
loads the company association.

I am confused that what exactly it does? Is it load the company object
in memory? and instead of going to database it takes it from memory.

Can anyone elaborate me what exactly happens when we use the :include
option.

Thanks,
Mike
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Hello and some clarity please before I start

2010-08-10 Thread Marnen Laibow-Koser
Hassan Schroeder wrote:
> On Mon, Aug 9, 2010 at 11:14 PM, mikertjones  
> wrote:
> 
>> However - massive snag! My hosting company, 1&1, does not support
>> development with the RoR framework. Thier message to me was:
>> 'At the moment we support the regular Ruby framework but not the Ruby
>> on Rails'
> 
> Ruby is a language, not a "framework". The statement above would be
> enough to send me off looking for a new hosting company.

Agreed; that's just completely clueless tech support.  As if there 
weren't already lots of reasons to abandon 1&1...

> 
>> My question is this:
>> Can I use Ruby on Rails as a local development framework and then
>> deploy the product of that work to my hosting server which supports
>> only Ruby?
> 
> No.

Well, maybe.  It depends on the the details of the hosts' Ruby 
installation.  But it probably won't be easy.

> 
>> In other words does the output from an RoR development
>> require RoR on the production server?
> 
> Yes.

Right.  It's not "output" in the conventional sense: since Ruby is 
interpreted, you need the interpreter there on the server, just like 
what you're used to with PHP.

The one exception would be if 1&1 supports Java.  You could compile your 
Rails app and the JRuby interpreter into a stand-alone Java servlet...

> 
>> If the answer is yes - RoR is required on the production server - then
>> I will either abandon RoR as a dev framework or find a new hosting
>> provider.
> 

As a former PHP developer myself, I'd say to find new hosting.  Rails is 
*amazing*.  For hosting, I recommend Heroku or Slicehost.

> Good luck with your decision :-)
> 
> --
> Hassan Schroeder  hassan.schroe...@gmail.com
> twitter: @hassan

Best,

-- 
Marnen Laibow-Koser
http://www.marnen.org
mar...@marnen.org

Sent from my iPhone
-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Routing, need fast help

2010-08-10 Thread Ainar Abramovich
Thanks very fast and useful answer, again Thanks

On Aug 10, 3:16 pm, Chris Mear  wrote:
> On 10 Aug 2010, at 13:10, Ainar Abramovich  wrote:
>
> > Hi, I try to do with my app something like twitter.com has, when you
> > are NOT logged in it shows twitter.com, when you are logged in it
> > keeps the same domain name in browser, but all page has been
> > changed(it's full with tweets), anybody? How to do this?
>
> You could just use an if statement in the controller action:
>
> if logged_in?
>   # set up logged-in stuff
>   render :action => 'some_template'
> else
>   # set up not-logged-in stuff
>   render :action => 'some_other_template'
> end
>
> Replace #logged_in? with whatever's appropriate for your authentication 
> system.
>
> Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Simple File Upload to a Blob column in a SQLite DB

2010-08-10 Thread Xenio
Hey Chris,

I think I sent a reply to just you by mistake. Is there anyway you can
post it here? Apparently I do not get copies of messages sent to
author only in google groups.

On Aug 9, 5:13 am, Chris Mear  wrote:
> On 9 August 2010 00:15, Xenio  wrote:
>
>
>
> > On Aug 8, 4:48 pm, Xenio  wrote:
> >> I have a DB that is already populated with data. There is a table
> >> called clubs that has an logo_big field set up as a blob. I have
> >> successfully used send_data to display the jpg pictures as I need them
> >> in the views. I just need to setup the edit/new view to enable me to
> >> upload the files.
>
> >> I tried paperclip but that requires changing the schema of the
> >> database which is not really an option for me.
>
> >> I am looking for a simple implementation to change the image file.
>
> >> I have been hunting around the "to_blob" and "send_data" parameters
> >> with no luck. Any help with this?
>
> > In my controller I have:
> >  # PUT /clubs/1
> >  # PUT /clubs/1.xml
> >  def update
> >   �...@club = Club.find(params[:id])
>
> >        if params[:club][:logo_big] && params[:club][:logo_big].size > 0
> >     �...@club.logo_big = params[:club][:logo_big].read
> >    end
>
> >    respond_to do |format|
> >      if @club.update_attributes(params[:club])
> >        flash[:notice] = 'Club was successfully updated.'
> >        format.html { redirect_to(@club) }
> >        format.xml  { head :ok }
> >      else
> >        format.html { render :action => "edit" }
> >        format.xml  { render :xml => @club.errors, :status
> > => :unprocessable_entity }
> >      end
> >    end
> >  end
>
> >  def image
> >        data = Club.find(params[:id]).data
> >        send_data data, :disposition => 'inline'
> >  end
>
> > In my edit view I have:
>
> > <% form_for (@club, :html => { :multipart => true }) do |f| %>
> >  <%= f.error_messages %>
>
> >  
> >    <%= f.file_field :logo_big %>
> >  
> >    <%= f.submit 'Update' %>
> >  
> > <% end %>
>
> > My DB has a table called clubs with a BLOB field called logo_big
>
> > When I click update I get an error along the lines of: "private method
> > `gsub' called for #"
>
> > What am i doing wrong? Did I mess up the syntax of the form? I'm
> > working off the generated views that Rails provides.
>
> The form looks fine, and your use of #read to get the file data looks
> right as well.
>
> What file/line are you getting the 'private method called' exception on?
>
> Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Routing, need fast help

2010-08-10 Thread Chris Mear
On 10 Aug 2010, at 13:10, Ainar Abramovich  wrote:

> Hi, I try to do with my app something like twitter.com has, when you
> are NOT logged in it shows twitter.com, when you are logged in it
> keeps the same domain name in browser, but all page has been
> changed(it's full with tweets), anybody? How to do this?

You could just use an if statement in the controller action:

if logged_in?
  # set up logged-in stuff
  render :action => 'some_template'
else
  # set up not-logged-in stuff
  render :action => 'some_other_template'
end

Replace #logged_in? with whatever's appropriate for your authentication system.

Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Routing, need fast help

2010-08-10 Thread Ainar Abramovich
Hi, I try to do with my app something like twitter.com has, when you
are NOT logged in it shows twitter.com, when you are logged in it
keeps the same domain name in browser, but all page has been
changed(it's full with tweets), anybody? How to do this?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Hello and some clarity please before I start

2010-08-10 Thread Hassan Schroeder
On Mon, Aug 9, 2010 at 11:14 PM, mikertjones  wrote:

> However - massive snag! My hosting company, 1&1, does not support
> development with the RoR framework. Thier message to me was:
> 'At the moment we support the regular Ruby framework but not the Ruby
> on Rails'

Ruby is a language, not a "framework". The statement above would be
enough to send me off looking for a new hosting company.

> My question is this:
> Can I use Ruby on Rails as a local development framework and then
> deploy the product of that work to my hosting server which supports
> only Ruby?

No.

> In other words does the output from an RoR development
> require RoR on the production server?

Yes.

> If the answer is yes - RoR is required on the production server - then
> I will either abandon RoR as a dev framework or find a new hosting
> provider.

Good luck with your decision :-)

-- 
Hassan Schroeder  hassan.schroe...@gmail.com
twitter: @hassan

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin

2010-08-10 Thread Colin Law
On 10 August 2010 09:54, Appu  wrote:
> Hi, i am using Savage Beast 2.3 plugin for the forum and i got and
> error
>
>
> undefined method `has_many' for Object:Class
>
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 9:in `included'
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 7:in `class_eval'
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 7:in `included'
> C:/forum/app/models/user.rb:2:in `include'
> C:/forum/app/models/user.rb:2
> C:/forum/app/controllers/users_controller.rb:16:in `create'

Showing us the code around this line might be useful.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Rails best practice to check an object ’s existence before displaying an attribute in a layout

2010-08-10 Thread Gudleik Rasch
ActiveRecord already has helper methods defined, so adding wrappers
like has_tag and get_first_tag is usually not necessary, and only
makes your code more complex.

1. You can do
 <% if post.tags.any? %>
   in the <%= post.tags.first.name %> category
 <% end %>
And remove the get_first_tag and tags methods from your model.

2. This kind of logic is well suited for the view layer (i think).

3. Hard to tell without knowing what tags actually returns. Try using
post.tags.inspect to see what it returns.
I suspect you see '#' because the objects in the array returned by
tags doesn't have a to_s method defined.
to_sentence converts an array to a string using to_s on each element.

If you have a Tag class, try adding this to that class:
def to_s
  name
end

If you're using a plugin/gem for the tags, you can either monkepatch
it or do something like this:
post.tags.map(&:name).to_sentence (assuming Tag has a name attribute
you want to display).
This kind of logic is appropriate to put in a helper.

--
gudleik

On Tue, Aug 10, 2010 at 1:23 AM, wtb  wrote:
> I have the following code in a layout:
>
> Posted <%=time_ago_in_words post.created_at %> ago
> <% if post.has_tag != nil %>
>   in the <%= post.get_first_tag.name %> category
> <% end %>
> And the following code in the post model which is inheriting form
> ActiveRecord::Base
>
> def has_tag
>  !self.tags.empty?
> end
>
> def get_first_tag
>  self.tags[0]
> end
> Tags is also inherited from ActiveRecord::Base and Post 'has_many'
> Tags
>
> Firstly: Is this the best way of checking if the post object has at
> least 1 associate tag attribute.
>
> Secondly: Should I be putting this logic into a helper method?
>
> Thirdly: Why doesn't the following work (it returns a # where the tags
> should be):
>
> in the <%= post.tags.to_sentence %> category,
> I guess its because tags aren't actually stored as an array attribute,
> but i don't really know.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] How do I optimize this query?

2010-08-10 Thread sprite
Right now I am wasting a query and also losing the order of Users. Was
wondering what t he proper way to do this query is?

@top_tipper_ids = Tip.find_by_sql("SELECT SUM(tips.amount_cents)
total_tip, tips.client_id FROM tips WHERE tips.vendor_id = #...@user.id}
GROUP BY tips.client_id ORDER BY total_tip").collect {|e| e.client_id}

@top_tippers = User.find_all_by_id(@top_tipper_ids)

Trying to find the top tippers (Users) for a specific vendor.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin

2010-08-10 Thread Chris Mear
On 10 August 2010 09:54, Appu  wrote:
> Hi, i am using Savage Beast 2.3 plugin for the forum and i got and
> error
>
>
> undefined method `has_many' for Object:Class
>
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 9:in `included'
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 7:in `class_eval'
> C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
> 7:in `included'
> C:/forum/app/models/user.rb:2:in `include'
> C:/forum/app/models/user.rb:2
> C:/forum/app/controllers/users_controller.rb:16:in `create'
>
>
> please help me to resolve this problem.

Does your User class inherit from ActiveRecord::Base?

Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] undefined method `has_many' for Object:Class +Savage Beast 2.3 plugin

2010-08-10 Thread Appu
Hi, i am using Savage Beast 2.3 plugin for the forum and i got and
error


undefined method `has_many' for Object:Class

C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
9:in `included'
C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
7:in `class_eval'
C:/forum/vendor/plugins/savage-beast/lib/savage_beast/user_init.rb:
7:in `included'
C:/forum/app/models/user.rb:2:in `include'
C:/forum/app/models/user.rb:2
C:/forum/app/controllers/users_controller.rb:16:in `create'


please help me to resolve this problem.

Thanks

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Merb configuration options in rails3

2010-08-10 Thread arai
Hey all,

I've used Rails v1 for a little while before switching to Merb, then
coming back again for rails3.  While using merb, I got really
comfortable using the config files to store configuration directives
that I wouldn't need to type at the command line when starting up
instances:

config/init.rb:
...
Merb::Config.use do |c|
  ...
  c[:adapter] = :thin
  c[:port] = 1234
  ...
end

As much fun as it is to type "rails s thin -p 1234", I'd rather just
use "rails s", or even "merb".  I've spent hours digging through
google and various documentation projects trying to figure this out,
how can I do this in rails3?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Dynamically creating the html for forms created by user in application.

2010-08-10 Thread Rtdp
hello,
In my rails application, a user creates a form by selecting the type
of the data i.e.(string, integer, text) and he then gives input filed
name for it.
i.e. if user wants Name as capition, txtname as input field name and
string as database field type the form will generated as -

Name: 



So how can create this html from this user given information. Is there
a plugin for this work ?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Updating a collection in a RESTful manne r…

2010-08-10 Thread flyerhzm
Here is an advise for "What is the Restful manner for updating a
collection?"

http://rails-bestpractices.com/questions/3-what-is-the-restful-manner-for-updating-a-collection

On 8月9日, 下午5时52分, Chris Mear  wrote:
> On 7 August 2010 22:07, Tim Harding  wrote:
>
>
>
> > Today I added a checkbox to each row of a table and a save button, to
> > perform an Archive operation on N items in the table.
>
> > This is essentially an update of the collection.
>
> > My initial thought was to PUT to students_path but only GET and POST
> > are allowed using the Rails RESTful routing.
>
> > I wound up adding an :collection => {:update_all => :put} to the
> > students routing and added an appropriate controller method.
>
> > I'm not terribly happy with this, stylistically, though,
> > pragmatically, it works.
>
> > What is the proper way to manage an update to a collection w/o having
> > to add an addition method to my controller?
>
> I don't think you can avoid having an additional method in the
> controller -- after all, the code required to update the collection is
> going to be different from any of your other actions. But you can
> avoid exposing the name of that new method in the URL.
>
> I would try manually defining a new PUT route outside of the existing
> resource map:
>
> map.connect 'students', :controller => 'students', :action =>
> 'update_collection', :conditions => {:method => :put}
>
> That should route correctly if you have a form with :url =>
> students_path, :method => :put.
>
> There may be a cleverer/neater way to do this within the resource map
> itself, but this at least is a good first thing to try.
>
> Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: where can I get up to date instantrails ?

2010-08-10 Thread Colin Law
On 10 August 2010 06:12, Dani Dani  wrote:
> thank you all.
>
> Aptana (RadRails) is an IDE. I'm looking for a ready package to install,
> soeting like InstantRails, but uptodate.
> Any ideas ?.

As Jason suggested, VirtualRails (http://www.virtualrails.org/) may be
a good way to go.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: Error: cross-thread violation on rb_gc()

2010-08-10 Thread Spong
I did some fiddling and this is what I'm getting:

$ gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 1.3.5
  - RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [universal-
darwin10.0]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/1.8
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/
Versions/1.8/usr/bin/ruby
  - EXECUTABLE DIRECTORY: /usr/bin
  - RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-10
  - GEM PATHS:
 - /Library/Ruby/Gems/1.8
 - /Users/sunpech/.gem/ruby/1.8
 - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8
  - GEM CONFIGURATION:
 - :update_sources => true
 - :verbose => true
 - :benchmark => false
 - :backtrace => false
 - :bulk_threshold => 1000
 - :sources => ["http://rubygems.org/";, "http://gems.github.com";]
  - REMOTE SOURCES:
 - http://rubygems.org/
 - http://gems.github.com

So ruby seems to be installed in two place: /usr/bin/ and /opt/local/
bin.  The former is the ruby that came with my Mac, and the latter
from MacPorts.  Should I not use MacPorts to install/update ruby?

On Aug 9, 2:53 pm, Spong  wrote:
> I think I did install multiple instances of Ruby.  How can I tell?
> And how can I remove the extra?
>
> Yes, I believe I did install one via MacPorts, and another manually.
> I'm also new to Macs.
>
> On Aug 9, 2:13 pm, Chris Mear  wrote:
>
>
>
> > On 9 August 2010 03:23, Spong  wrote:
>
> > > I don't like cross-posting, but there doesn't seem to be much activity/
> > > response to my question on StackOverflow.
>
> > > Link to 
> > > SO:http://stackoverflow.com/questions/3413209/error-cross-thread-violati...
>
> > > Question:
>
> > > I'm new to Ruby on Rails.
>
> > > I ran the following in a terminal when I was going through creating a
> > > blog tutorial with Rails:
>
> > > $ rails blog
> > > [BUG] cross-thread violation on rb_gc()
> > > (null)
>
> > > Abort trap
>
> > > How do I determine what this error message means and how to fix it?
>
> > > Is there something wrong with a gem installed?
>
> > > $ gem list
>
> > > *** LOCAL GEMS ***
>
> > > actionmailer (2.3.8)
> > > actionpack (2.3.8)
> > > activerecord (2.3.8)
> > > activeresource (2.3.8)
> > > activesupport (2.3.8)
> > > colored (1.2)
> > > crack (0.1.8)
> > > json (1.4.3)
> > > pusher (0.5.3)
> > > rack (1.2.1, 1.1.0)
> > > rails (2.3.8)
> > > rake (0.8.7)
> > > ruby-hmac (0.4.0)
> > > signature (0.1.1, 0.1.0)
> > > sinatra (1.0)
> > > sqlite3-ruby (1.3.1, 1.3.0)
> > > webmat-git_remote_branch (0.3.0)
>
> > > $ gem env
> > > RubyGems Environment:
> > >  - RUBYGEMS VERSION: 1.3.7
> > >  - RUBY VERSION: 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]
> > >  - INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
> > >  - RUBY EXECUTABLE: /opt/local/bin/ruby
> > >  - EXECUTABLE DIRECTORY: /opt/local/bin
> > >  - RUBYGEMS PLATFORMS:
> > >    - ruby
> > >    - x86-darwin-10
> > >  - GEM PATHS:
> > >     - /opt/local/lib/ruby/gems/1.8
> > >     - /Users/sunpech/.gem/ruby/1.8
> > >  - GEM CONFIGURATION:
> > >     - :update_sources => true
> > >     - :verbose => true
> > >     - :benchmark => false
> > >     - :backtrace => false
> > >     - :bulk_threshold => 1000
> > >     - :sources => ["http://rubygems.org/";, "http://gems.github.com";]
> > >  - REMOTE SOURCES:
> > >     -http://rubygems.org/
> > >     -http://gems.github.com
>
> > This smells like a borked Ruby installation, or multiple Ruby
> > installations conflicting with each other, or something like that.
>
> > Have you installed Ruby multiple times? How did you install the Ruby
> > you're using in /opt/local/bin? MacPorts, I'm guessing?
>
> > Chris

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Re: Locking Images in HTML Files..can use it on ROR also

2010-08-10 Thread Colin Law
On 10 August 2010 04:52, Jeffrey Bonson  wrote:
> Thank you all,for your VALUABLE information.
> I didn't find what i needed in this forum and many newbies are using
> this as a reference. That's why i posted this. Why don't u guys prove
> what u have written with some CODES, so that it becomes useful to OTHERS
> as well.

You never actually asked a question, which may be why you did not get
much help.  You showed some html and javascript and described what it
achieves.  Rails can of course generate any html and javascript that
you like.

Perhaps you should start again and explain what it is that you want to know.

Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



Re: [Rails] Re: Paperclip - Amazon S3 - https

2010-08-10 Thread Colin Law
On 10 August 2010 01:29, Sandy  wrote:

Please don't top post, it makes it difficult to follow the thread.
Insert your reply at appropriate points in the previous mail.  Thanks.

> Daniel,
>
> While I'm sure that you had good intentions, the tutorial to which you
> referred is absolutely unrelated to the question I asked.
>
> Specifically, I clearly stated that I know how to use Paperclip to
> upload files to S3, and to create a url to retrieve the files.  My
> question was whether anyone knew of a tutorial relating to https, as I
> am interested in being able to control access to the uploadeed files.
>
> In the future, may I suggest that no answer is better than a wrong
> answer or guess, which simply makes others, who may know the answer,
> refrain from looking at the question.

I don't think that getting shirty with those trying to help is likely
to get you anywhere.  Often those reading mail only have time to skim
messages and may make suggestions that they think may be helpful, but
may not turn out to be so.  You might to better by gracefully pointing
out that the suggestion does not help and ask for further suggestions.

Colin

>
> Sandy
>
> On Aug 9, 3:15 pm, Daniel Alejandro Gaytán Valencia
>  wrote:
>> Take a look at:
>>
>> http://scottmotte.com/archives/181.html
>>
>> Regards,
>> Daniel Gaytán
>> 
>>
>> 2010/8/9 Sandy 
>>
>>
>>
>> > I am able to use Paperclip to save files to Amazon's S3 storage.  Once
>> > saved, the files are available using a URL associated with the bucket
>> > and filename.
>>
>> > I have not been able to find a good tutorial which clearly explains
>> > how to save a file to S3 (using Paperclip) whereby it can only be
>> > retrieved using https, and only for a limited time period (which I
>> > understand is a function of S3).
>>
>> > My specific need is to upload the file from one web page, while
>> > allowing a user (who has logged into the site) to then (for a limited
>> > amount of time) to access that page using https and a link on a page
>> > served to that user.
>>
>> > Does anyone have good tutorial or example code which addresses this
>> > issue?
>>
>> > --
>> > You received this message because you are subscribed to the Google Groups
>> > "Ruby on Rails: Talk" group.
>> > To post to this group, send email to rubyonrails-t...@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > rubyonrails-talk+unsubscr...@googlegroups.com
>> > .
>> > For more options, visit this group at
>> >http://groups.google.com/group/rubyonrails-talk?hl=en.- Hide quoted text -
>>
>> - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-t...@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.