为什么这种导轨简单不起作用?

时间:2013-10-21 20:16:04

标签: ruby-on-rails forms routes simple-form rails-routing

我正在制作一个rails应用程序。用户注册后(我已经使用设计创建了用户注册),他们可以填写此表单,其中包含他们的个人资料信息。我已经好几次这样做了,我找不到有什么问题。这是模型:

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

我收到以下错误,对我来说没有任何意义:

#&lt;#:0x007f9c00c7b3e0&gt;

的未定义方法`information_index_path'

有谁知道如何解决这个问题?感谢。

更新:

当我做rake路由时,对于信息#create,表格应该是什么,它有一个空白路径。还有信息#index,这就是我现在想的。如何获取信息#create路径是否为空?

3 个答案:

答案 0 :(得分:0)

请尝试在视图的第6行和第9行中删除评论(#符号)。他们可能会搞乱ERB处理。

答案 1 :(得分:0)

你能试试informations_path吗?请参阅here

答案 2 :(得分:0)

问题在于命名资源信息。由于信息是复数,因为它是单数,这是令人困惑的轨道。我重命名了模型描述和控制器描述控制器,它起作用了。