用户可以编辑他的帐户并有一个菜单来选择他的社区:
<%= form_for @user, :html => { :multipart => true } do |f| %>
<%= f.collection_select :community_id, Community.find(:all,
:include => :memberships,
:conditions => ['memberships.user_id = ? and memberships.role > ?', @user.id, '0' ]),
:id,
:name,
:style => "width: 200px;" %>
<% end %>
我想把这个菜单放在显示页面上,让他有可能直接切换。
使用rails 2,我使用observe_field或:onchange =&gt; 'this.form.onsubmit()'我不知道java ...
答案 0 :(得分:0)
<%= form_for @user, :remote => true do |f| %>
<%= f.collection_select :community_id,
Community.where('memberships.user_id = ? and memberships.role > ?', @user.id, '0').includes(:memberships), :id, :name,{},
:onchange => "this.form.submit();" %>
<% end %>
将'this.form.onsubmit()更改为'this.form.submit()