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/. 
>
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.

-- 
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/b96962c5-d04d-4e5d-b37c-92c7bc2f57b8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to