简体   繁体   中英

form_for details not displaying in view :Ruby on Rails

Hi I am using simple form_for to create new object but on the ads/new.html.erb on h1 tag is displayed but form's information is missing

Here is my new.html.erb file contents

<h1>New Ad</h1>
<% form_for(@ad ,:url=>{:action=>'create',method: :post}) do |f| %>
<p>
<b>Name:</b> <%= f.text_field:name %>
</p>
<p>
<b>Description:</b><%= f.text_area:description %>
</p>
<p>
<b>Price:</b><%= f.text_field:price %>
</p>
<p>
<b>Seller Id:</b><%= f.text_field:seller_id %>
</p>
<p>
<b>Email Address:</b><%= f.text_field:email %>
</p>
<p><%= f.submit "Create Ad" %>
</p>
<% end %>

This line

<% form_for(@ad ,:url=>{:action=>'create',method: :post}) do |f| %>

should be like this

<%= form_for(@ad ,:url=>{:action=>'create',method: :post}) do |f| %>

You are missing = sign

Reference,see the API

Additional note

I guess you can refactor it to

<%= form_for(@ad) do |f| %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM