I have been trying to pick up rails and I am having trouble passing
parameters through a link_to tag so as to retrieve records where there
is a parameter match.
On Monday, August 11, 2014 3:33:19 AM UTC+1, Ruby-Forum.com User wrote:
Hi guys,
I have been trying to pick up rails and I am having trouble passing
parameters through a link_to tag so as to retrieve records where there
is a parameter match.
If you’re trying to get the result of all those checkboxes why not use a
form?
First: you should not use *params *method in your views, it is only
available in a controller as a Hash to get values from views. Second: you should just use a symbol to indicated the key to are
going
to pass from the view to the controller; I mean do not use :employee.id
but :employee_id. Third: as for Rails 2.3.8 API http://api.rubyonrails.org/v2.3.8/,
you
can specify link_to as follows:
You should replace retrieve_case by the appropriate value that is
available
in the veiw. In your controller you will get this value from the 'params
hash:
patams[:employee_id]
Fourth: do not forget to change the routes (routes.rb file) to enable
the
called controller action.
I’d recommend getting this form to work with a real submit button and
without AJAX before complicating it.
Also: 2.3.5 is deeply, wildly out-of-date. At a minimum, you should
upgrade
to the last security release of 2.3.x as there are SEVERE issues in
older
versions.
because that’s how the MVC pattern works, you passing values (via params
hash) from your view to your controller which extracts the needed
parameters values, processes them by making call to your model if
needed,
initialises/changes instance variables and passes them again to the view
and displays them. Why to use params hash in a view if you can pass in
the
variables from the controller ? Doing like that, you are ‘breaking’ in
some
way the described pattern as well as Rails convention. Try to follow
Rails
guides (http://guides.rubyonrails.org) to have an idea about how it
works
and it will become more clear and easy for you.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.