If I have <select name="user[city]"> what is params[:???] params[:user[city]] ??? -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
params[:user][:city] NAYAK On Sun, Jan 11, 2009 at 12:04 AM, Gi Ga <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>wrote:> > If I have <select name="user[city]"> what is params[:???] > > params[:user[city]] ??? > -- > Posted via http://www.ruby-forum.com/. > > > >-- - NAYAK --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@city = params[:user][:city] Why I get: You have a nil object when you didn''t expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] Even if I try: @city = params[:user][:city] if params[:user][:city] I get same error. -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
James Bond wrote:> @city = params[:user][:city] > > Why I get: > > You have a nil object when you didn''t expect it! > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] > > Even if I try: > > @city = params[:user][:city] if params[:user][:city]@city = params[:user][:city] if params[:user] nil propagation indeed sucks, but if you have no [:user], you can''t have a [:user][:city]. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Phlip wrote:> James Bond wrote: >> @city = params[:user][:city] if params[:user][:city] > @city = params[:user][:city] if params[:user] > > nil propagation indeed sucks, but if you have no [:user], you can''t have > a > [:user][:city].Why this doesn''t work: @city = params[:user][:city] | "xxx" Same error. -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try || not | On Jan 10, 2009, at 12:11 PM, James Bond wrote:> > Phlip wrote: >> James Bond wrote: >>> @city = params[:user][:city] if params[:user][:city] >> @city = params[:user][:city] if params[:user] >> >> nil propagation indeed sucks, but if you have no [:user], you can''t >> have >> a >> [:user][:city]. > > Why this doesn''t work: > > @city = params[:user][:city] | "xxx" > > Same error. > -- > 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
cloper wrote:> Try || not |Same error :( -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
@city = params[:user][:city] if params[:user] && params[:user][:city]Should do the trick NAYAK On Sun, Jan 11, 2009 at 1:59 AM, James Bond < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > cloper wrote: > > Try || not | > > Same error :( > -- > Posted via http://www.ruby-forum.com/. > > > >-- - NAYAK --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Look at your server''s log, you can find the parameters for each request. eg. Processing XxxController#update (for 127.0.0.1 at 2009-01-10 14:44:03) [GET] Session ID: 4598628b1689321ec39c1b22fb0e7728 Parameters: {"param1"=>"...", "param2"=>"...", ...} Jej --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Vishwanath Nayak wrote:> @city = params[:user][:city] if params[:user] && > params[:user][:city]Should > do the trickYes it do, but it not simple any more, as it was before. For example: This works in old rails versions, but not in (2.2.2), why? @word = params[:search][:word] || params[:word] || "home" The are 2 parameters, one POST and another GET (POST overwrite GET), if there not POST and GET, defaul value is: "home" How can I do it in Rials 2.2.2? -- 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> @word = params[:search][:word] || params[:word] || "home"you can still do that. there is only a problem if params[:search] is nil. because then you''d try to evaluate nil.[] which again leads to an error. this is what Phlip wanted to tell you way up in this thread. --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MaD is right, no matter what the expression, you will always get an exception if you try to evaluate nil.[] You can divide the expression in two: city = (params[:user]) ? params[:user][:city] || "xxx" : "xxx" Cheers, Sazima On Jan 11, 10:07 am, MaD <mayer.domi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > @word = params[:search][:word] || params[:word] || "home" > > you can still do that. there is only a problem if params[:search] is > nil. because then you''d try to evaluate nil.[] which again leads to an > error. this is what Phlip wanted to tell you way up in this thread.--~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MaD wrote:>> @word = params[:search][:word] || params[:word] || "home"> you can still do that. there is only a problem if params[:search] is > nil. because then you''d try to evaluate nil.[] which again leads to an > error. this is what Phlip wanted to tell you way up in this thread.And if James Bond''s posts still don''t reflect that awareness, I did not want to get into... @word = params.fetch(:search, params).fetch(:word, ''home'') Another fix - both the GET and POST flavors of this action should have the same params, meaning the both things which hit the action from a web browser should put their goodies into :search=>{} block. That''s a best practice... --~--~---------~--~----~------------~-------~--~----~ 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-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---