我正在制作一个 Rails 应用程序。用户注册后(我已经使用 devise 创建了用户注册),他们可以填写包含其个人资料信息的表格。表单应该向信息控制器中的创建操作提交一个发布请求,但由于某种原因,我无法正确配置路由。当我运行 rake 路由时,对于 informations#create,这是表单应该去的,它有一个空白路径。还有informations#index,我猜这就是它现在的样子。如果路径为空白,如何让表单转到 informations#create?我已经这样做了好几次了,我找不到问题所在。这是模型:
class Information < ActiveRecord::Base
belongs_to :user
end
这是控制器:
class InformationsController < ApplicationController
def new
@information = Information.new
end
def create
@information = Information.create(params[:information])
redirect_to student_path
end
def index
end
end
这是新操作的视图。
<div class="span6 offset3 text-center">
<h1>Edit your information</h1>
<%= simple_form_for @information do |f| %>
<%= f.input :skills %>
<%= f.input :looking_for, :label => 'What help do you need?' %>
<%= f.input :my_idea %>
<%= submit_tag "Save", :class => "btn btn-primary btn-large" %>
<% end %>
</div>
这是路由文件中的行:
resources :informations
我收到以下错误:
#<#:0x007f9c00c7b3e0> 的未定义方法“information_index_path”
这是文件的 rake 路线
informations GET /informations(.:format) informations#index
POST /informations(.:format) informations#create
这是我尝试加载显示表单的页面时的完整堆栈跟踪:
Started GET "/informations/new" for 127.0.0.1 at 2013-10-21 17:25:09 -0400
Processing by InformationsController#new as HTML
Rendered informations/new.html.erb within layouts/application (64.2ms)
Completed 500 Internal Server Error in 70ms
ActionView::Template::Error (undefined method `information_index_path' for #<#<Class:0x007ff03e8b34a0>:0x007ff03e8b23e8>):
2: <div class="span6 offset3 text-center">
3: <h1>Edit your information</h1>
4:
5: <% simple_form_for @information do |f| %>
6: <%= f.input :skills %>
7:
8:
app/views/informations/new.html.erb:5:in `_app_views_informations_new_html_erb__3172218935119285240_70334909089600'
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms)
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.1ms)
Started GET "/informations/new" for 127.0.0.1 at 2013-10-21 17:25:09 -0400
Processing by InformationsController#new as HTML
Rendered informations/new.html.erb within layouts/application (8.3ms)
Completed 500 Internal Server Error in 13ms
ActionView::Template::Error (undefined method `information_index_path' for #<#<Class:0x007ff03e8b34a0>:0x007ff03e8708a8>):
2: <div class="span6 offset3 text-center">
3: <h1>Edit your information</h1>
4:
5: <% simple_form_for @information do |f| %>
6: <%= f.input :skills %>
7:
8:
app/views/informations/new.html.erb:5:in `_app_views_informations_new_html_erb__3172218935119285240_70334908978600'
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.3ms)
Rendered /usr/local/rvm/gems/ruby-2.0.0-p247@firehose/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (14.0ms)