Jump to content

The ultimate community for Ruby on Rails developers.


Photo

How to retrieve attributes in param hash...


  • Please log in to reply
3 replies to this topic

#1 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 18 November 2013 - 11:55 PM

Its easy to get a value our of a param hash, however I just implemented a select combo box such as this:

 

[background='']<%= select("category", "skill_id", @job_categories.map {|u| [u.name,u.id]}) %>

 

and the "category" and "skill_id" appear as follows in the param hash noting its outside of the { and }.  I've tried category = user_params[:category] but this resolved to nil

 

  Parameters: {"utf8"=>"Γ£ô", "authenticity_token"=>"oSjjxvuOgUQsqpYUnh8eigZwnwgFXC0PGzxhKPFoOvg=", "user"=>{"name"=>"2", "email"=>"jay.schr
ock@gmail.com", "address"=>"15019 Senator Way", "city"=>"Carmel", "state"=>"AK", "zip"=>"46032", "mobile_phone"=>"(317)-250-0627", "mobile_p
hone_type"=>"I", "birth_date"=>"07/02/2013", "ss_num"=>"310-12-0000", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "user
_type"=>"P"}, "category"=>{"skill_id"=>"1"}, "commit"=>"Save changes", "id"=>"41"}

 

Any ideas?



#2 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 19 November 2013 - 12:32 AM

I figured it out, my bad..  I was quering user_params  given my model is a user and in user controller..  Anyway, I needed to look at the varaible params to find the non-user attributes.. 



#3 Kevin

Kevin

    Signalman

  • Members
  • 21 posts

Posted 21 November 2013 - 08:53 AM

so the problem is solved ?



#4 jschrock1

jschrock1

    Dispatcher

  • Members
  • 48 posts
  • LocationIndianapolis

Posted 21 November 2013 - 03:10 PM

I figured it out, my bad..  I was quering user_params  given my model is a user and in user controller..  Anyway, I needed to look at the varaible params to find the non-user attributes.. 

Yes its solved, I screwed up, not realizing that user_params is a method in my controler (I knew that but wasn't thinking that at the time), thought rails was doing some magic...  I just needed to acces the parameters via params[...]






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users