What part doesn’t seem to work?
Could it be fixed if you structured the code as:
if params[:user_id].blank? blah_blah_blah else if current_user.id.to_s == params[:user_id]
blah_blah
else blah end end
–wpd
What part doesn’t seem to work?
Could it be fixed if you structured the code as:
if params[:user_id].blank? blah_blah_blah else if current_user.id.to_s == params[:user_id]
blah_blah
else blah end end
–wpd
Yep, I did that, I get this error
"Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id"
Patrick Doyle wrote:
Did you call logged_in? before current_user to make sure that it is
valid?
-Rob
Hi --
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
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'
Aha! OK, what is on line 8? (If that doesn't solve it for you, paste
the first part of the galleries_controller.rb up to the end of the
index method.)
-Rob
Hi --
Hmm! If the I Sign in to the site. I type the url "mysite.com/galleries" I get a different error
"undefined method `elseif' for #<GalleriesController:0x3517a18>"
Mohammad Abed wrote:
Hi --
Hmm! If the I Sign in to the site. I type the url "mysite.com/galleries" I get a different error
Getting a different error is always a hopeful sign ![]()
"undefined method `elseif' for #<GalleriesController:0x3517a18>"
It's elsif (no second e).
David