我很新于编程,正在尝试使用paperclip将用户照片添加到我的用户记录中。可以从添加新记录表单创建记录,没有<%= f.file_field :photo %>行并正确重定向并保存记录到数据库。但是,当它包含在保存中时,它想要重定向到create.html.erb而不是用户路径,并且不保存新记录。它也不显示任何错误。我已经更新了用户表的photo_file_name、photo_content_type和:photo_file_size字段。此外,我正在运行Windows,如果这有任何帮助。
模型:
class User < ActiveRecord::Base
has_many :venues
has_many :reviews
has_attached_file :photo,
:styles => {
:medium => "300x300>",
:thumb => "100x100>" }
end
控制器:
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.create(params[:user])
if @user.save
flash[:notice] = 'User added'
redirect_to users_path
else
@user.save
end
end
def show
@user = User.find(params[:id])
end
end
查看:
<% form_for (@user, :html => { :multipart => true }) do |f| %>
<p>username: <br>
<%= f.text_field :username %></p>
<p>password: <br>
<%= f.text_field :password %></p>
<p>photo: <br>
<%= f.file_field :photo %></p>
<%= submit_tag %>
<% end %>
非常感谢您的帮助!
开发日志中显示的内容:
处理 UsersController#create(对于 127.0.0.1,时间为 2011-01-12 22:05:56 的 POST 请求) 参数:{"user"=>{"photo"=>#, "username"=>"nghjhg", "password"=>"ghjghj"}, "commit"=>"Save changes", "authenticity_token"=>"IlacpnqsC/iJ+41bx8tN4obOWPgirMx810l/WvohN68="} [paperclip] identify -format %wx%h "C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png[0]" 2>NUL [paperclip] 处理时发生错误:
C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png 无法被 'identify' 命令识别。> [paperclip] identify -format %wx%h "C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png[0]" 2>NUL [paperclip] 处理时发生错误:
C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png 无法被 'identify' 命令识别。> 在布局文件 layouts/application 中呈现模板,在 users/create 中呈现 完成时间 157ms(视图渲染时间:4ms,数据库查询时间:0ms) | 200 OK [http://localhost/users]