0
<% @company.comments.each do |comment| %>
<tr>
<td><%= comment.commenter %></td>
<td><%= comment.body %></td>
<td><%= time_ago_in_words(comment.created_at, "Comment") %> ago</td>
<td><%= comment.commentfile %></td>
</tr>
<% end %>
是我想显示从下面的表格上传的文件:载波问题 - 文件没有显示?
<h2>Add a comment:</h2>
<%= form_for([@company, @company.comments.build]) do |f| %>
<div class="hidden">
Name:<br />
<%= f.text_field :commenter, :value => current_user.full_name, :readonly => "readonly" %>
</div>
<div class="field">
Comment:<br />
<%= f.text_area :body %>
</div>
<div class="field">
<%= f.file_field :commentfile %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
,但我不知道该文件是否被保存东阳当我检查我的公共/上传文件夹中没有文件出现。在<%= comment.commentfile %>
的视图中,我得到了我上传的文件的名称,但不知道文件的位置或我如何链接到该文件,或者文件是否甚至上传了?开始认为它只是插入了一个字符串。我的模特如下。
class Comment < ActiveRecord::Base
belongs_to :contact
belongs_to :company
mount_uploader :commentfile, CommentFileUploader
end
和comment_file_uploader.rb
class CommentFileUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
请帮帮忙!
另外需要注意的,如果我做
u = Comment.new
u.commentfile = params[:file]
在控制台我得到
NameError: undefined local variable or method `params' for main:Object
迁移补充说:commentfile
class CreateUploader < ActiveRecord::Migration
def self.up
add_column :comments, :commentfile, :string
end
def self.down
end
end
当您提交表单时,日志中的任何内容? – Chowlett