In RoR, is there an easy way to prevent the view from outputting <p> tags?
I'm new to Ruby and Rails and I have a simple controller that shows an item from the database in a default view. When it is displaying in HTML it is outputting <p>
tags along with the text content. Is there a way to prevent this from happening? I suppose if there isn't, is there at least a way to set the default css class for the same output in a statement such as this:
<% @Items.each do |i| %>开发者_JS百科
<%= i.itemname %>
<div class="menu_body">
<a href="#">Link-1</a>
</div>
<% end %>
So the problem is with the <%= i.itemname %>
part. Is there a way to stop it from wrapping it in its own <p>
tags? Or set the css class for the output?
Thanks!
You need to enclose it with the HTML tag of your choice. Also if required you can escape bad code by using <%=h i.itemname %>
Example:
<% @Items.each do |i| %>
<div><%=h i.itemname %></div>
<div class="menu_body">
<a href="#">Link-1</a>
</div>
<% end %>
Edit: Ryan Bigg is right. Rails doesn't output a <p>
tag. Sorry for the wrong info.
You canchange the public/stylesheets/scaffold.css if you want.
Or if you want to change it for a single page say items/index.html.erb
<style>
p{
/* your style here *?
}
</style>
精彩评论