我的表单出现问题,我在帮助下解决了第一个问题,但现在我收到新错误,说我有一个未定义的方法。仍在学习 RoR,所以如果这听起来很愚蠢,请多多包涵,感谢您的帮助。
这是代码:
<h1>Create New Contact</h1>
<% form_for :contact, :url => { :action => 'create' } do |f| %>
<p><label for="contact_first_name">First Name:</label>
<%= f.text_field 'contact', 'first_name' %></p>
<p><label for="contact_last_name">Last Name:</label>
<%= f.text_field 'contact', 'last_name' %></p>
<p><label for="contact_address">Address:</label>
<%= f.text_field 'contact', 'address' %></p>
<p><label for="contact_city">City:</label>
<%= f.text_field 'contact', 'City' %></p>
<p><label for="contact_state">State:</label>
<%= f.text_field 'contact', 'state' %></p>
<p><label for="contact_country">Country:</label>
<%= f.text_field 'contact', 'country' %></p>
<p><label for="contact_phone">Phone:</label>
<%= f.text_field 'contact', 'phone' %></p>
<p><label for="contact_email">Email:</label>
<%= f.text_field 'contact', 'email' %></p>
<%= f.submit "Create" %>
<% end %>
<p><%= link_to 'Back', { :action => 'index' } %></p>
这是我得到的错误,
NoMethodError in Contact#new
Showing C:/rails_projects/contactlist/app/views/contact/new.html.erb where line #4 raised:
undefined method `merge' for "first_name":String
Extracted source (around line #4):
1: <h1>Create New Contact</h1>
2: <% form_for :contact, :url => { :action => 'create' } do |f| %>
3: <p><label for="first_name">First Name:</label>
4: <%= f.text_field 'contact', 'first_name' %></p>
5:
6: <p><label for="contact_last_name">Last Name:</label>
7: <%= f.text_field 'contact', 'last_name' %></p>
Rails.root: C:/rails_projects/contactlist
Application Trace | Framework Trace | Full Trace
app/views/contact/new.html.erb:4:in `block in _app_views_contact_new_html_erb___976580590_43916136'
app/views/contact/new.html.erb:2:in `_app_views_contact_new_html_erb___976580590_43916136'
Request
Parameters:
None
Show session dump
Show env dump
Response
Headers:
None