Ruby on rails 如何使用线程将回形针启用为可注释回形针?

Ruby on rails 如何使用线程将回形针启用为可注释回形针?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我已经安装了回形针,它与我自己创建的模型配合得很好。 我试着用这个模型做同样的事情,它是由名为acts\u as\u commentable\u的gem通过线程创建的 但是,它从不保存存储图片的文件名。但它会像往常一样保存评论。 这真的很奇怪,它只是不采取回形针文件上传 为什么? models/comment.rb(当然,我已经迁移了comment表中的必填列) views/users/show.html.erb <%= render 'comment', :user => @use

我已经安装了回形针,它与我自己创建的模型配合得很好。
我试着用这个模型做同样的事情,它是由名为acts\u as\u commentable\u的gem通过线程创建的 但是,它从不保存存储图片的文件名。但它会像往常一样保存评论。
这真的很奇怪,它只是不采取回形针文件上传

为什么?

models/comment.rb(当然,我已经迁移了comment表中的必填列)

views/users/show.html.erb

<%= render 'comment', :user => @user %>
<%=form_for :users, url: url_for( :controller => :users, :action => :add_comment ) do |f| %>

    <div class="field">
      <%= f.label :body %><br />
      <%= f.text_field :body %>
    </div>
    <div class="field">
    <%= f.file_field :comment_icon %>
    </div>
  <div class="actions">
    <%= f.submit %>
  </div>

<% end %>
def add_comment
    @user = User.find_by_username(params[:id])
    @user_who_commented = current_user
    @comment = Comment.build_from( @user, @user_who_commented.id, params[:users][:body] )
    @comment.save
    redirect_to :controller => 'users', :action => 'show', :id => @user.username
    flash[:notice] = "comment added!"
end




def delete_comment
    @comment = Comment.find(params[:id])

    if current_user.id == @comment.user_id
        @comment.destroy
        flash[:notice] = "Deleted!"
    else
        flash[:notice] = "Sorry, you can't delete this comment"
    end
    redirect_to :controller => 'users', :action => 'show', :id => params[:username]
end
models/comment.rb(由acts作为可注释的线程自动创建)

这是评论模型的一部分。在我的用户操作中添加评论时,这是否重要

  # Helper class method that allows you to build a comment
  # by passing a commentable object, a user_id, and comment text
  # example in readme
  def self.build_from(obj, user_id, comment)
    c = self.new
    c.commentable_id = obj.id
    c.commentable_type = obj.class.base_class.name
    c.body = comment
    c.user_id = user_id
    c
  end

尝试在
@comment之前添加此行。在
add\u comment
操作中保存

@comment.comment_icon = params[:users][:comment_icon]

请添加
add\u comment
用户控制器的操作的代码。请添加
@comment。在
@comment之后保存附件。保存
并告诉我发生了什么。@AhmadSherif我这样做了。它只创建新注释,但没有附件:(
@comment.comment_icon = params[:users][:comment_icon]