Reputation: 563
I'm getting back into rails after a hiatus, and ERB is not rendering as expected. I opened a view from a brand-new project, and one from an old project in both chrome and firefox. Same problem in all four permutations.
Here's _form.html.erb
<%= form_for(@cat) do |f| %>
<% if @cat.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@cat.errors.count, "error") %> prohibited this cat from being saved:</h2>
<ul>
<% @cat.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :birth_date %><br>
<%= f.date_select :birth_date %>
</div>
<div class="field">
<%= f.label :color %><br>
<%= f.text_field :color %>
</div>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :sex %><br>
<%= f.text_field :sex %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
And here's new.html.erb
<h1>New Cat</h1>
<%= render 'form' %>
<%= link_to 'Back', cats_path %>
And here's what the browser renders:
I'm running rails 4.2.1 and ruby 2.2.1, and I'm brand new to both versions.
Upvotes: 0
Views: 1721
Reputation: 563
Turns out, I was opening the ERb files in the browser in the manner I'd grown accustomed to doing for HTML files (Command + O -> choose file). No wonder it was being read as HTML!
For posterity: you must navigate to your app directory in the terminal, start a rails server with "rails s", and navigate to your views from localhost:3000.
Upvotes: 1
Reputation: 11628
I think you might have a lingering new.html
in your views
directory.
Upvotes: 0