Thanks for the advice David, I did remove the code from the controller.
I've looked the stack trace. What is interesting, it does generate the
correct sql. Unfortunately, I don't understand enough about RoR to
decipher the log
**********************
Processing GalleriesController#index (for 127.0.0.1 at 2009-01-21
13:56:31) [GET]
Parameters: {"action"=>"index", "controller"=>"galleries"}
Gallery Load (2.0ms) SELECT * FROM `galleries`
RuntimeError (Called id for nil, which would mistakenly be 4 -- if you
really wanted the id of nil, use object_id):
/app/controllers/galleries_controller.rb:8:in `index'
/vendor/rails/actionpack/lib/action_controller/base.rb:1253:in
`send'
/vendor/rails/actionpack/lib/action_controller/base.rb:1253:in
`perform_action_without_filters'
/vendor/rails/actionpack/lib/action_controller/filters.rb:617:in
`call_filters'
/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in
`perform_action_without_benchmark'
/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure'
/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in
`perform_action_without_rescue'
/vendor/rails/actionpack/lib/action_controller/rescue.rb:136:in
`perform_action_without_caching'
/vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:13:in
`perform_action'
/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in
`cache'
/vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in
`cache'
/vendor/rails/actionpack/lib/action_controller/caching/sql_cache.rb:12:in
`perform_action'
/vendor/rails/actionpack/lib/action_controller/base.rb:524:in `send'
/vendor/rails/actionpack/lib/action_controller/base.rb:524:in
`process_without_filters'
/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in
`process_without_session_management_support'
/vendor/rails/actionpack/lib/action_controller/session_management.rb:134:in
`process'
/vendor/rails/actionpack/lib/action_controller/base.rb:392:in
`process'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:183:in
`handle_request'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:110:in
`dispatch_unlocked'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:123:in
`dispatch'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in
`synchronize'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:122:in
`dispatch'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:132:in
`dispatch_cgi'
/vendor/rails/actionpack/lib/action_controller/dispatcher.rb:39:in
`dispatch'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:76:in
`process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in
`synchronize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/rails.rb:74:in
`process'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
`process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
`process_client'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`initialize'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`new'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:282:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in
`each'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/configurator.rb:281:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:212:in
`run'
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281
/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load_without_new_constant_marking'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:142:in
`load'
/vendor/rails/railties/lib/commands/servers/mongrel.rb:64
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:521:in
`new_constants_in'
/vendor/rails/activesupport/lib/active_support/dependencies.rb:153:in
`require'
/vendor/rails/railties/lib/commands/server.rb:49
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
`require'
script/server:3
David A. Black wrote:
> Hi --
>
> On Wed, 21 Jan 2009, Mohammad Abed wrote:
>
>> That is not necessary, Now I get the same error for the first if clause
>> (when the param is null, and I just type "mysite.com/galleries", the
>> other two clauses work ok. This what my code looks like
>>
>> if params[:user_id].blank?
>> @galleries = Gallery.find(:all, :conditions => ['visibility_status =
>> ?', true])
>
> I'm not sure how that if clause can give a "called id on nil" error,
> since it doesn't call id. Can you examine the stacktrace and see if
> you can pinpoint it?
>
> Also, though I know this isn't your question, I'd advise putting all
> of this logic in the model(s). For example:
>
> class User < AR::Base
> has_many :galleries
> has_many :visible_galleries,
> :class_name => "Gallery",
> :conditions => ["visibility_status = ?", true]
>
> Then you can do:
>
> @galleries = user.visible_galleries
>
> or something like that, in the controller, instead of in-lining the
> business logic of the model.
>
>
> David
>
> --
> David A. Black / Ruby Power and Light, LLC
> Ruby/Rails consulting & training: http://www.rubypal.com
> Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)
>
> http://www.wishsight.com => Independent, social wishlist management!
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---