Ruby on rails rails表单中未定义的方法接触路径
我的路线定义如下Ruby on rails rails表单中未定义的方法接触路径,ruby-on-rails,Ruby On Rails,我的路线定义如下 get 'contacts/new', to: 'contacts#new' def new @contact = Contact.new end 在我的ContactsController中,我定义如下 get 'contacts/new', to: 'contacts#new' def new @contact = Contact.new end 在views contacts/new/_form.html.erb中,我构建了如下表单 <%= form
get 'contacts/new', to: 'contacts#new'
def new
@contact = Contact.new
end
在我的ContactsController中,我定义如下
get 'contacts/new', to: 'contacts#new'
def new
@contact = Contact.new
end
在views contacts/new/_form.html.erb中,我构建了如下表单
<%= form_for @contact, html: {multipart:true} do |f| %>
<%= f.label :username %>
<%= f.text_field :username %>
<% end %>
当我在routes文件中定义了rails时,你知道为什么rails会抛出这样的错误吗。我只是想了解rails路由的内部工作原理为了避免此类错误,请删除路由并使用:
resources :contacts, only: [:new, :create]
要避免此类错误,请删除路由并使用:
resources :contacts, only: [:new, :create]
尽量使用railsy-way,如@Graham提到的
resources
或
尽量使用railsy-way,如@Graham提到的
resources
或
为联系人创建一个post类型的路由(这是一个抛出错误) 或者取消这条路线
get 'contacts/new', to: 'contacts#new'
简单地加上这个
resources :contacts
为联系人创建一个post类型的路由(这是一个抛出错误) 或者取消这条路线
get 'contacts/new', to: 'contacts#new'
简单地加上这个
resources :contacts
将控制器返回到
get'contacts/new',返回到:'contacts#new'
,然后在控制台上键入:rake routes
。然后将路由更改为get'contacts/new',更改为:'contacts#new',如:'contact'
,然后再次键入rake routes
。比较结果将控制器返回到获取'contacts/new',返回到:'contacts#new'
,然后在控制台上键入:rake routes
。然后将路由更改为get'contacts/new',更改为:'contacts#new',如:'contact'
,然后再次键入rake routes
。比较结果