2009-12-19 76 views
0

我有一個關於博客製作 問題,我需要的東西喜歡的網站railcast 這是之前進入的頭銜,我會看到後進入與限排, 索引頁面描述標題只看到完整的段落 我沒有這樣做關於博客和節目介紹一個索引並顯示所有

My index View :: 

<% for post in @posts %> 
    <div class="blogPost"> 
     <h2> 
      <%= link_to h(post.title), post %> 
     </h2> 
      <b>Category:</b><%=h post.category.category_name %><br/> 
      <b>Posted at:</b><%=h post.date_of_creation %><br/> 
      <%= "#{post.comments.count} Comments" %><br/> 
     <div class="body"> 
      <p><%= post.description %></p> 
      <p><%=link_to "Read More...", post %></p> 
     </div> 
     <div class="action"> 
      <%= link_to "Edit", edit_post_path(post) %> 
      <%= link_to "Destroy", post, :confirm => 'Are you sure?', :method => :delete %> 
     </div> 
    </div> 

My controller :: 
def index 
    @posts = Post.paginate :per_page => 5, :page => params[:page], :order => 'created_at DESC' 

    respond_to do |format| 
     format.html # index.html.erb 
     format.js do 
     render :update do |page| 
      page.replace_html 'post', :partial => "post" 
     end 
     end 
     format.xml { render :xml => @posts } 
     format.json { render :json => @posts } 
     format.atom 
    end 
    end 

New Post Form :: 
<h1>New post</h1> 

<% form_for(@post) do |f| %> 
    <%= f.error_messages %> 

    <p> 
    <%= f.label :title %><br /> 
    <%= f.text_field :title %> 
    </p> 
    <p> 
    <%= f.label :body %><br /> 
    <%= f.text_area :body %> 
    </p> 
    <p> 
    <%= f.label :date_of_creation %><br /> 
    <%= f.date_select :date_of_creation %> 
    </p> 
    <p> 
    <label for="category">Category<br/></label> 
    <select name="category"> 
     <% @cat.each do |category| %> 
     <option value="<%= category.id %>"> 
     <%= category.category_name %> 
     </option> 
     <% end %> 
    </select> 
    </p> 
    <p> 
    <%= f.submit 'Create' %> 
    </p> 
<% end %> 

是,我需要創建一個新的列調用說明或者什麼 我沒有在這裏與

<div class="body"> 
      <p><%= post.description %></p> 
      <p><%=link_to "Read More...", post %></p> 
     </div> 

蓋伊調用它,有什麼更好的主意嗎? Thx for reply〜

回答

0

我找到了使用truncate方法的解決方案。