2013-03-10 60 views
0

我試圖在我的Ruby on Rails網站上實現一個評論系統。 我基本上遵循這個線程的這些準則:Micropost's comments on users page (Ruby on Rails)當您的RoR網站顯示文本「資產」時,這意味着什麼?

但是,評論不顯示當我發佈和文本「資產」顯示在每個評論框的頂部。這是從哪裏來的?

與代碼更新時間: 我使用的三種模式,試圖獲得工作的意見如在上面的鏈接

user.rb

class User < ActiveRecord::Base 
has_many :microposts, dependent: :destroy 
    has_many :comments 

micropost.rb

class Micropost < ActiveRecord::Base 
    attr_accessible :content, :image, :comment_content 
    belongs_to :user 
    has_many :comments, dependent: :destroy 
    validates :user_id, presence: true 
    validates :content, presence: true 

    default_scope order: 'microposts.created_at DESC' 

    def self.from_users_followed_by(user) 
    followed_user_ids = "SELECT followed_id FROM relationships 
         WHERE follower_id = :user_id" 
    where("user_id IN (#{followed_user_ids}) OR user_id = :user_id", 
      user_id: user.id) 
    end 
end 

comment.rb

class Comment < ActiveRecord::Base 
    attr_accessible :comment_content 

    belongs_to :user 
    belongs_to :micropost 

    validates :comment_content, presence: true 
    validates :user_id, presence: true 
    validates :micropost_id, presence: true 
end 

評論控制器

class CommentsController < ApplicationController 
    def create 
    @micropost = Micropost.find(params[:micropost_id]) 
    @comment = Comment.new(params[:comment]) 
    @comment.micropost = @micropost 
    @comment.user = current_user 
    if @comment.save 
     redirect_to(:back) 
    else 
     render 'shared/_comment_form' 
    end 
    end 
end 

控制器微柱

class MicropostsController < ApplicationController 
    before_filter :signed_in_user 
    before_filter :correct_user, only: :destroy 

    def create 
    @micropost = current_user.microposts.build(params[:micropost]) 
    if @micropost.save 
     flash[:success] = "Posted" 
     redirect_to root_path 
    else 
     @feed_items = [] 
     render 'static_pages/home' 
    end 
    end 

    def destroy 
    @micropost.destroy 
    redirect_to root_path 
    end 

    private 

    def correct_user 
     @micropost = current_user.microposts.find_by_id(params[:id]) 
     redirect_to root_path if @micropost.nil? 
    end 
end 

用戶控制器

def show 
    @user = User.find(params[:id]) 
    @microposts = @user.microposts.paginate(page: params[:page]) 
    @comment = Comment.new 
    end 

評論形式

<%= form_for([micropost, @comment]) do |f| %> 

routes.rb中

resources :microposts do 
    resources :comments 
end 

鑑於微柱

<li> 
    <span class="content"><%= simple_format(micropost.content) %></span> 
    <%= image_tag micropost.image_url(:thumb).to_s %><br> 
    <span class="timestamp"> 
    Posted <%= time_ago_in_words(micropost.created_at) %> ago. 
    </span> 
<%= render 'shared/comment_form', micropost: micropost %> 
<% if current_user?(micropost.user) %> 
    <%= link_to "delete", micropost, method: :delete, 
            confirm: "You sure?", 
            title: micropost.content %><br> 

    <% end %> 
</li> 

回答

1

也許你有你的泛音一個或形式控制一些靜態信息是使您的評論textarea的?

檢查您查看控制器或者它是在'static_pages/home'

編輯的話: 就全搜索項目文本資產,也許你找到一個圖片的alt =「資產」標籤的圖像和圖像不可用。

+0

你認爲這是與圖像的東西?我發佈了最重要的微博視圖 – 2013-03-10 08:59:20

+0

如果我理解你正確的話,你說你的表單中有一個文本「資產」。所以它呈現在某個地方。檢查你的'shared/comment_form',也許有一個佔位符文本。 OR:它是圖像的alt標記,圖像不可用,因此alt文本被渲染。 – YvesR 2013-03-10 09:08:10

+0

是的,那就是我所問的。但是,我沒有任何地方可以在任何地方使用「資產」文本。使用我的鼠標光標在顯示的頁面上甚至無法突出顯示文字 – 2013-03-10 09:31:06