我有ProjectsController,我在那里添加了一个名为search_for_members的方法我希望这个方法在用户点击通过ajax提交时用成员名称更新div这里的问题是我收到路由错误
没有路线匹配[POST]“/ projects / 47”
任何帮助?
的routes.rb
resources :projects do
resources :user_stories
get '/projects/:project_id/searchformembers' => 'projects#searchformembers'
end
视图/项目/显示
<%= form_tag :url => {:action => "search_for_members"} , :method => 'get', :remote => true do%>
<div>
<%= text_field_tag :search, params[:search], :class => 'form-control', :placeholder => 'User name'%>
</div>
<%= submit_tag "Add user", :name => nil, :class => "btn btn-info"%>
<% end%>
<div id="members">
<%= render @users %>
<% end %>
projects_controller
def search_for_members
if (params[:search])
@users = User.search(params[:search], @project).page(params[:page]).per_page(4)
else
@users = @project.users
end
respond_to do |format|
format.js
end
end
答案 0 :(得分:1)
您的路线定义错误,与您的控制器或form_for
用法不匹配。像这样改变你的路线:
resources :projects do
get :search_for_members, :on => :member
end
然后在您的视图中更新您的form_for
定义,如下所示:
<%= form_tag search_for_members_project_path(@project), :method => 'get', :remote => true do%>
你应该全力以赴。