当您的RoR网站上显示“资产”文字时,这意味着什么?

时间:2013-03-10 08:17:58

标签: ruby-on-rails ruby ruby-on-rails-3

我尝试在Ruby on Rails网站上实现评论系统。 我基本上遵循了这个主题的指导原则:Micropost's comments on users page (Ruby on Rails)

但是,当我发布时,评论不会显示,并且每个评论框顶部都会显示“资产”文本。这是从哪里来的?

更新了代码: 我正在使用三个模型来尝试使评论正常工作,如上面的链接

所示

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 个答案:

答案 0 :(得分:1)

也许你的某个部分或表单控件中有一些静态信息会为你的textarea提供评论?

检查您是否查看控制器,或者它可能位于'static_pages/home'

编辑: 只需在您的项目中搜索文本资产,也许您会找到一个图像alt =&#34; assets&#34;标记图像,图像不可用。