查看:
<p>
<%= form.label :FirstName %>
<%= form.text_field :FirstName %>  
<%= form.label :LastName %>
<%= form.text_field :LastName %>
</p>
<br>
<%= form.label :PhoneNo %>
<%= form.text_field :PhoneNo %>
<p>
<%= form.label :Lane1 %>
<%= form.text_field :Lane1 %>  
<%= form.label :Lane2 %>
<%= form.text_field :Lane2 %> <br>
<%= form.label :ZipCode %>
<%= form.text_field :zipcode %>  
<%= form.label :State %>
<%= form.select(:State, options_for_select([['Alaska','AK'],['Alabama','AL'], ['Arkansas','AR'],['Arizona','AZ'],['California','CA'],['Colorado','CO'],['Connecticut','CT'],['District of Columbia','DC'],['Delaware','DE'],['Florida','FL'],['Georgia','GA'],['Hawaii','HI'],['Iowa','IA'],['Idaho','ID'],['Illinois','IL'],['Indiana','IN'],['Kansas','KS'],['Kentucky','KY'],['Louisiana','LA'],['Massachusetts','MA'],['Maryland','MD'],['Maine','ME'],['Michigan','MI'],['Minnesota','MN'],['Missouri','MO'],['Mississippi','MS'],['Montana','MT'],['North Carolina','NC'],['North Dakota','ND'],['Nebraska','NE'],['New Hampshire','NH'],['New Jersey','NJ'],['New Mexico','NM'],['Nevada','NV'],['New York','NY'],['Ohio','OH'],['Oklahoma','OK'],['Oregon','OR'],['Pennsylvania','PA'],['Rhode Island','RI'],['South Carolina','SC'],['South Dakota','SD'],['Tennessee','TN'],['Texas','TX'],['Utah','UT'],['Virginia','VA'],['Vermont','VT'],['Washington','WA'],['Wisconsin','WI'],['West Virginia','WV'],['Wyoming','WY']])) %>
<%= form.label :County %>
<%= form.text_field :County %>
</p>
<p>
<%= form.submit %>
</p>
<% end %>
(第1行,第2行,邮政编码和国家/地区未保存)
控制器:
class CustomersController < ApplicationController
def index
@customers = Customer.all
end
def show
@customer = Customer.find(params[:id])
end
def new
end
def create
@customer = Customer.new(customer_params)
@customer.save
redirect_to @customer
end
private
def customer_params
params.require(:customer).permit(
:FirstName, :LastName, :PhoneNo, :Line1, :Line2, :ZipCode, :State, :Country)
end
end
// sjhfkljifeui; eisdhABCNFJWHEkywqoka; cns,M bhwdgshcwlnq
答案 0 :(得分:0)
在您的customer_params方法中,您允许:Line1,:Line2,:ZipCode 但在你的视图中它是:Lane1,:Lane2,:zipcode 所以它不接受它们。你可以用两种类型修复它。
您可以解决此问题(仅当您要接受所有属性时才提及)(脏的方式)
def customer_params
params.require(:customer).permit!
端
答案 1 :(得分:-1)
试试这个:
<p>
<%= form.label :FirstName %>
<%= form.text_field :FirstName %>  
<%= form.label :LastName %>
<%= form.text_field :LastName %>
</p>
<br>
<%= form.label :PhoneNo %>
<%= form.text_field :PhoneNo %>
<p>
<%= form.label :Line1 %>
<%= form.text_field :Line1 %>  
<%= form.label :Line2 %>
<%= form.text_field :Line2 %> <br>
<%= form.label :ZipCode %>
<%= form.text_field :ZipCode %>  
<%= form.label :State %>
<%= form.select(:State, options_for_select([['Alaska','AK'],['Alabama','AL'], ['Arkansas','AR'],['Arizona','AZ'],['California','CA'],['Colorado','CO'],['Connecticut','CT'],['District of Columbia','DC'],['Delaware','DE'],['Florida','FL'],['Georgia','GA'],['Hawaii','HI'],['Iowa','IA'],['Idaho','ID'],['Illinois','IL'],['Indiana','IN'],['Kansas','KS'],['Kentucky','KY'],['Louisiana','LA'],['Massachusetts','MA'],['Maryland','MD'],['Maine','ME'],['Michigan','MI'],['Minnesota','MN'],['Missouri','MO'],['Mississippi','MS'],['Montana','MT'],['North Carolina','NC'],['North Dakota','ND'],['Nebraska','NE'],['New Hampshire','NH'],['New Jersey','NJ'],['New Mexico','NM'],['Nevada','NV'],['New York','NY'],['Ohio','OH'],['Oklahoma','OK'],['Oregon','OR'],['Pennsylvania','PA'],['Rhode Island','RI'],['South Carolina','SC'],['South Dakota','SD'],['Tennessee','TN'],['Texas','TX'],['Utah','UT'],['Virginia','VA'],['Vermont','VT'],['Washington','WA'],['Wisconsin','WI'],['West Virginia','WV'],['Wyoming','WY']])) %>
<%= form.label :County %>
<%= form.text_field :County %>
</p>
<p>
<%= form.submit %>
</p>