我尝试使用: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
答案 0 :(得分:1)
在new
def new
@info1 = Info1.new
end
同时更改
<%= form_for @info1 do |f| %>
注意强>
另外,我建议您使用正确的命名约定来避免此类错误
这样,
Info1
重命名为Information
,将文件名重命名为information.rb
Info1Controller
重命名为InformationsController
,将文件名重命名为informations_controller.rb
路线到
resources :informations