On Monday, August 11, 2014 4:33:19 AM UTC+2, 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. 
>
> https://gist.github.com/Brayoni/3102c5dab7f76b1cee7b 
>
> Here is my view; 
> <% @employees.each do |employee| %> 
>
>         <div class="name_list<%=cycle('odd', 'even')%>"><li> 
>             <label><%= check_box_tag "retrieve_case[employee_ids]", 
> employee.id, false,:class=>'right' %> 
>                 <div class="att_list_names"><%= employee.first_name 
> %></div> </label> 
>         </li>  </div> 
>     <% end %> 
> </div> 
>
> <%= link_to "#{t('retrieve_case')}", {:controller => 
> 'employee_indisciplines', :action => 'show_indisciplines', :employee.id 
> => params[:retrieve_case]}, { :class => 'submit_button' }, :method => 
> 'post' %> 
>
>
> controller method; 
>   def show_indisciplines 
>     if request.post? 
>       activated_ids = params[:retrieve_case][:employee_ids].collect 
> {|employee_id| employee_id.to_i} 
>
>       if activated_ids 
>         @employee_indiscipline = 
> EmployeeIndiscipline.find_all_by_employee_id(params[:employee_id]) 
>       end 
>     end 
>   end 
>
> -- 
> Posted via http://www.ruby-forum.com/. 
>

*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:

<%= link_to "#{t('retrieve_case')}", {:controller => 
'employee_indisciplines', :action => 'show_indisciplines', 
:employee_id => retrieve_case, { :class => 'submit_button' }, :method => 
'post' %> 



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.

-- 
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/13970854-87fe-4ef2-bcef-d1c4655af9bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to