目的:實現透過前段網頁提交並保存一個一個company對象,這個對像只有一個字段,那就是name.
但是提交時保存卻說:找不到lname方法! controller保存時並沒有設計lname方法,也不知道為什麼會回報這個錯誤。
2天了,沒弄清楚。
下面是報錯:
NoMethodError in CompaniesController#create
undefined method `lname' for #
Extracted source (around line #23):
21 def create
22 @company = Company.new(params[:company].permit(:name))
23 @company.save
24 redirect_to @company
25 end
Rails.root:
Application Trace | Framework Trace | Full Trace
app/controllers/companies_controller.rb:23:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"3DISc2IKH23W5KUHORMza5NHm9eMq35KDdbrbus6LqDXNVGVku0vsI2QyJ2LopGD1TlMgR>Dwid* 1"},
"commit"=>"Create Company"}
<h1>New Company</h1>
<%= form_for(@company) do |f| %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.submit "Create Company" %>
</p>
<% end %>
<% content_for :aside do %>
<% render 'sidebar' %>
<% end %>
companies_controller.rb
def create
@company = Company.new(params[:company].permit(:name))
@company.save
redirect_to @company
end