<%= form_for @ in1 do | f | %GT; Info1#new中的ArgumentError

时间:2017-02-10 07:18:19

标签: ruby-on-rails

我尝试使用:Info1它显示表单,但它又给出了方法错误 我知道这是一个小小的愚蠢错误,但请指出。 new.html.erb代码            

添加新记录

       <%= form_for@Info1 do |f| %>
       <p>
       <%=f.label :address %><br/>
       <%=f.text_field :address %><br/>
       </p>
       <p>
       <%=f.label :state %><br/>
       <%=f.text_field :state %><br/>
       </p>


        <p>
        <%=f.submit "Submit"%>
        </p>
        <%end%>

控制器代码如下     class Info1Controller&lt; ApplicationController的     def创建     @info1 = Info1.new(in1)     if @ info1.save     redirect_to users_path,:notice =&gt; &#34;学生详细信息保存&#34;     其他     渲染&#34;新&#34;     结束     端

def new

end

def in1
params.require(:info1).permit(:address, :state)
end

end

1 个答案:

答案 0 :(得分:1)

new

中添加此内容
def new
  @info1 = Info1.new
end

同时更改

<%= form_for @info1 do |f| %>

注意

另外,我建议您使用正确的命名约定来避免此类错误

这样,

  1. 将模型从Info1重命名为Information,将文件名重命名为information.rb
  2. 将控制器从Info1Controller重命名为InformationsController,将文件名重命名为informations_controller.rb
  3. 路线到

    resources :informations