要成为会员,用户可以使用按钮在社区页面上创建会员资格。这是在部分创建一个新的“会员” memberships_controller:
@community = Community.find(params[:community_id])
@community.memberships.create(:user => current_user, :role => 1)
在视图中:
<% form_remote_tag :url => community_memberships_path(@community) do %>
<%= submit_tag 'Join' %>
<% end %>
升级到Rails 3之后,这不再起作用了!
我试过了:
<% form_tag( {:url => community_memberships_path(@community)}, :remote => true) do %>
和此:
<% form_tag :url => {:controller => '/memberships/new', :action => :create,:community_id => @community }, :remote => true do %>
但没有机会..并且有这个错误
没有路线匹配“/ communities / 2
寻求帮助
答案 0 :(得分:1)
URL是第一个参数,选项是次要的。
<% form_tag(community_memberships_path(@community), :remote => true) do %>
...
至于您的No route matches
异常,请检查您是否正确地将路由转换为Rails 3语法。