尝试在以下示例代码上执行simple_form_for

时间:2013-07-09 16:08:24

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

我是ruby-on-rails的新手,并尝试将以下form_tag重构为simple_form_for代码,我在日志中得到了一个奇怪的错误:

"customers_customers_customers_path' no methods found.

知道代码的哪一部分是错的?

<%= form_tag  projects_path, :method => 'get', :id => "ajax_search_form" do %>
...
<% end %>

我将它重构为:

<%= simple_form_for @projects, :html => { :id => 'ajax_search_form' }, :method => 'get' do |f| %>

...
<% end %>

我做错了什么?

1 个答案:

答案 0 :(得分:0)

simple_form_for主要用于将表单与form_for一样关联到模型。在您的代码中,您使用form_tag与路径关联,而不是模型。在这里实现simple_form_for的正确方法是:

<%= simple_form_for :projects, :url => projects_path, :method => 'get', :id => "ajax_search_form" do $>
...
<% end %>