Em Sta
Em Sta

Reputation: 1696

Form labels not displaying

Im new to ruby on rails and actually i read a starter book! The thing is that there was an example how to make an new entra in the database with an form in the new.html.erb So the example goes like this

<% @title = "neu" %>
 <h2>Neuen Favorit erstellen</h2>
<% form_for :bookmark, :url => {:action => "create"} do |f| %>
<p>
 <label for="bookmark_title">Titel</label>
<%= f.text_field :title %>
</p>
<p>
<label for="bookmark_url">URL</label>
<%= f.text_field :url %>
 </p>
<p>
 <label for="bookmark_comment">Kommentar</label>
<%= f.text_area :comment %>
</p>
 <p>
 <%= submit_tag "speichern" %>
 </p>
 <% end %>
<p><%= link_to "Zurück zur Liste", :action => "index" %></p>

Somehow only the title, <h2>, and the last <p> is displayed in the browser! Nothing of the form is displayed! Thanks for help! Greetings from Germany

Upvotes: 0

Views: 374

Answers (2)

aceofbassgreg
aceofbassgreg

Reputation: 3937

You should be using <%=, not <%, to start all lines except for where you're ending your form. An example:

<%= form_for @order_item do |f| %>
  <div class="field">
<%= f.select(:product_id, options_for_select(Product.all.collect {|p| ["#{p.color} - 
     #{p.size}", p.id ] })) %>
  </div>
  <div class="field">
<%= f.label :quantity %>
<%= f.number_field :quantity %>
  </div>
  <div class="actions">
<%= f.submit "Add to Cart" %>
   </div>
<% end %>

Upvotes: 1

Zippie
Zippie

Reputation: 6088

Change:

<% form_for

to

<%= form_for

Also, as Ryan said, use f.label to make your code cleaner, like this:

<%= f.label :url, "URL" %>

Upvotes: 3

Related Questions