Reputation: 127
Display only the first 50 characters <%= news.header %>
view:
<% @news.each do |news| %>
<div class="news">
<div class="title"> <%= news.title %> </div>
<div class="photo"><%= image_tag( "1.jpg", :width =>247, :crop => :fit) %> </div>
<div class="header"> <%= news.header %></div>
<div class="cl"></div>
</div>
<% end %>
controller:
def index
@news=News.all
end
Upvotes: 0
Views: 788
Reputation: 19879
<%= news.header.truncate(50) %>
See http://api.rubyonrails.org/v4.2.7/classes/String.html#method-i-truncate
Upvotes: 2