仅显示前50个字符<%= news.header%>
视图:
<% @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 %>
控制器:
def index
@news=News.all
end
答案 0 :(得分:1)
--
-- Table structure for table `recent_viewed`
--
CREATE TABLE IF NOT EXISTS `recent_viewed` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`postID` int(11) NOT NULL,
`memberID` int(11) NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `recent_viewed`
--
--
-- Table structure for table `posts`
--
CREATE TABLE IF NOT EXISTS `posts` (
`postID` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(70) NOT NULL,
`name` varchar(32) NOT NULL,
`city` varchar(32) NOT NULL,
`created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`postID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Dumping data for table `posts`
--
请参阅http://api.rubyonrails.org/v4.2.7/classes/String.html#method-i-truncate