2011-06-03 34 views
0

用户可以编辑自己的帐户,并有一个菜单来选择他的社区:Rails 3的切换菜单重新加载页面时更改数据

<%= 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 %> 

我希望把节目页面上此菜单,给他的可能性直接切换。

随着轨道2,我用的observe_field或:平变化=> 'this.form.onsubmit()',我不知道java的...

回答

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()