索引中form_for的未定义方法“cmdb_searches_path”

时间:2015-06-04 05:00:36

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

我有一个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。我没有定义任何特定的路线,只有资源路线。这之前有用,但对于这个它没有用。

2 个答案:

答案 0 :(得分:0)

由于您是从索引操作渲染表单,因此它不知道create操作。将form_for修改为:

 form_for @cisearch, :url => your_create_action,remote:true

答案 1 :(得分:0)

resources :cmdb_searches添加到您的routes.rb