On 2 February 2014 06:22, Bizt <[email protected]> wrote: > I've been trying to set default URL parameters in the controller, which will > also be used within the view. This is what I've got: > > @params = params > > defaults = { :date_from => '21/1/21014', :date_to => '21/2/21014', > :data=>"Expense" } > if @params.any? > @params = defaults.merge(@params) > else > @params = defaults > end > > .. seems messy, and doesn't work :( When params are present it still uses > the default params.
That is likely because it should be params not @params. I don't think you need the .any? test either, just let it merge the empty hash into defaults. If you need to do this in more than one controller method then use a before filter. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLssBVkcsP-6XHxbyWG85PGn3y%3D%3DNyX0qYB1EPO2FzCv5Q%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.

