Jump to content

The ultimate community for Ruby on Rails developers.


Photo

params["sort_dir"] ||= 'asc'

params rails_4_upgrade

  • Please log in to reply
2 replies to this topic

#1 moiseszaragoza

moiseszaragoza

    Passenger

  • Members
  • 1 posts

Posted 30 August 2013 - 08:09 PM

I am trying to upgrade from rails 3.1.1 to rails 4 and i have this 1 line of code that used to work fine that no longer works.

params["sort_dir"] ||= 'asc'

I know i can do

if params["sort_dir"] && params["sort_dir"].empty?
  params["sort_dir"] = 'asc'
end 

but this code appers way to many times on my code to replace them all and its on multiple fields

 

What should i do?



#2 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 31 August 2013 - 02:06 AM

Can you post the params hash that comes into the controller where you are seeing the problem. Not sure why that is no longer working and I'd like to run a few console tests.

 

If it is not possible to solve the problem (I'm wondering if this a ruby version issue hence wanting to ruin some tests) then you could consider writing a before filter in your application controller to look for the params and stuff them into something that will work for you without having to change all your controller methods. (OO Rocks :))


Programming is just about problem solving!


#3 Ohm

Ohm

    Guard

  • Members
  • 186 posts
  • LocationCopenhagen

Posted 31 August 2013 - 05:09 PM

Hmm, in my Rails 4 project I am able to do

params['this_value'] ||= 'that'
raise params.inspect

just fine. This results in an runtime error with the following params:

{"controller"=>"home", "action"=>"index", "this_value"=>"that"}

Calling http://localhost:300...s_value=no_this instead, yield the expected result

{"this_value"=>"no_this", "controller"=>"home", "action"=>"index"}

Blog: http://ohm.sh | Twitter: madsohm





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users