简单形式未定义的方法路径

时间:2016-01-08 22:00:32

标签: ruby-on-rails

我是使用简单表格的新手。一开始我想做一个简单的表格。

#country_controller
def edit
  @country = Country.find(params[:id])  
end

#edit.html.erb
<%= simple_form_for @country do |f| %>
  <%= f.input :username %>
  <%= f.input :password %>
  <%= f.button :submit %>
<% end %>

但是我收到了这个错误

undefined method `country_path' for #<#<Class:0x007fdb21098e00>:0x007fdb2108cad8>

我的路线

 management GET    /management(.:format)                              management/home#index
             management_settings GET    /management/settings(.:format)                     management/settings#list
        management_country_index GET    /management/country(.:format)                      management/country#index
         edit_management_country GET    /management/country/:id/edit(.:format)             management/country#edit
              management_country PATCH  /management/country/:id(.:format)                  management/country#update
                                 PUT    /management/country/:id(.:format)                  management/country#update
                                 DELETE /management/country/:id(.:format)                  management/country#destroy

2 个答案:

答案 0 :(得分:4)

由于您的路由稍微不符合标准,因此您需要将网址明确传递给simple_form_for

<%= simple_form_for @country, url: management_country_path(@country) do |f| %>

答案 1 :(得分:1)

据推测,您正在使用scope

<%= simple_form_for [:management, @country] do |f| %>

您还可以使用polymorphic_path

<%= simple_form_for @country, url: polymorphic_path([:management, @country]) do |f| %>