Ruby on Rails Saturday, February 1, 2014

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. Not sure where it's going wrong and search on google yields many varieties. I know using default values in methods is something that I will repeat again so I was wondering what the best practise is for handling this. Thanks

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/b28b477a-bbfe-4b78-9592-e08cba2484f7%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment