我无法理解在使用 Ruby on Rails 时如何触发特定按钮事件。例如,我在表格中有一个迷你表单(MVC 的视图侧):
<%= form_tag do %>
<% if student.floor_pref == '1st' %>
<td><%= select_tag 'room', options_for_select(@first_floor.map { |value| [value,value]}, @selected_room) %></td>
<% end %>
<% if student.floor_pref == '2nd' %>
<td><%= select_tag 'room', options_for_select(@second_floor.map { |value| [value,value]}, @selected_room) %></td>
<% end %>
<% if student.floor_pref == '3rd' %>
<td><%= select_tag 'room', options_for_select(@third_floor.map { |value| [value,value]}, @selected_room) %></td>
<% end %>
<td><%= submit_tag 'Update' %></td>
<% end %>
我如何告诉控制器,当在视图中单击更新按钮时,例如执行此代码:
a = Student.find(3)
a.room_number = '2105'
a.save