开发者

Question about checkbox on Ruby on Rails

开发者 https://www.devze.com 2023-01-10 19:16 出处:网络
I\'m developing a website fo开发者_StackOverflow社区r my University and I got a problem. There is a page where I have the list of all students of the university. The admin can select some students th

I'm developing a website fo开发者_StackOverflow社区r my University and I got a problem.

There is a page where I have the list of all students of the university. The admin can select some students that will be able to go to a selective process and then he have to see them in other separate page.

How can I do that using Ruby On Rails?

Thanks,

Hugo Henley


Hi If you want use checkboxes you should write inside your form something similar to <td><%= check_box_tag "user_ids[]", "#{user.id}", true%><%= user.name%></td> then you'll get array od user ids as an params[:user_ids] and you may show only this users on other page


<h1>in your view </h1>

By checking those ones using checkboxes you can get the id's of those students like this
<%= check_box_tag "user_ids[]", "#{user.id}", true%>

passing those id's into the respective controller action

@users = User.where(:id => params[:user_ids])

Display those object details in to the required webpage using @users.each 
<% @users.each do |user| %>
  <%= user.name %>
<%end%>
0

精彩评论

暂无评论...
验证码 换一张
取 消