我有一个cmdbs_controller.rb,里面有索引和定义的cmdb资源路由:
def index
@cisearch = CmdbSearch.new
end
我还有一个cmdb_search模型,这是搜索表单的模型(空)。在我的index.html.erb中,我想像这样加载form_for:
<%= form_for @cisearch, remote:true do |f| %>
...some code..
<% end %>
我以前对另一个页面做过这样的搜索,但现在我得到了一个错误:
undefined method `cmdb_searches_path'
编辑:没有cmdb_search控件,cmdb_model是为建立搜索表单而创建的,只是暂时使用。一个成功的例子:我以前就是这样做的,它成功了:
#requests_controller.rb
def index
if !user_signed_in?
redirect_to new_user_session_path
else
@requests = Request.search(params[:search]).order("#{sort_column} #{sort_direction}").where("payed = ?", false).order(created_at: :desc).paginate(per_page: 20, page: params[:page])
@search = Search.new
end
end然后我有了搜索模型。在requests/index.html.erb中,我有:
<%= form_for @search, remote: true do |f| %>
.. some code
<% end %>
其工作方式是,我在requests_controller中创建了一个搜索模型实例,以便能够创建form_for @search。我没有定义任何具体的路由,只定义了资源路由。这在以前是有效的,但对于这一次它不起作用。
发布于 2015-06-04 14:20:33
因为您是从index操作呈现表单,所以它不知道create操作。将form_for修改为:
form_for @cisearch, :url => your_create_action,remote:true发布于 2015-06-04 14:32:25
将resources :cmdb_searches添加到您的routes.rb
https://stackoverflow.com/questions/30635256
复制相似问题