我正在尝试创建一个新用户并使用回形针上传一张图片。它将登录名、电子邮件和密码传递到数据库,但不传递照片详细信息。谁能看到我哪里出错了?我正在使用 rails 3.06 和 ruby 1.9.2
这是来自 show.html.erb
<div id="pic"><%= image_tag @user.photo.url(:main) %></div>
这是来自 user.rb
class User < ActiveRecord::Base
attr_accessible :photo
has_attached_file :photo, :styles => {:small => "70x70>", :main => "250x250>" },
:url => "public/system/photos/:id/:style/:basename.:extension"
这是在 edit.html.erb 上使用的形式,它可以工作,而 new.html.erb 不工作
<%= form_for @user, :html => {:multipart => true} do |f| %>
<div class="field">
<%= f.label :login %><br />
<%= f.text_field :login %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.text_field :password %>
</div>
<p>
<%= f.file_field :photo %>
</p>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
这是来自 users_controller.rb
def create
@user = User.new
@user.login = (params[:user][:login])
@user.email = (params[:user][:email])
@user.password = (params[:user][:password])
@user.photo_file_name = (params[:user][:photo_file_name])
@user.photo_content_type = (params[:user][:photo_content_type])
@user.photo_file_size = (params[:user][:photo_file_size])
这是终端输出
在 2013-06-08 13:18:58 +0100 开始 POST "/users" for 127.0.0.1 +0100 由 UsersController#create 作为 HTML 参数处理:{"utf8"=>"✓", "authenticity_token"=>"4Qvx+ aPv9fpOQYk7aAv5iupoBA8aPBYelcjQPh4aM2I=", "user"=>{"login"=>"meme", "email"=>"me@me.com", "password"=>"[FILTERED]", "photo"=>#> }, "commit"=>"Create User"} 用户负载 (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 User Load (0.5ms) SELECT "users" ."id" FROM "users" WHERE ("users"."login" = 'meme') LIMIT 1 User Load (0.3ms) SELECT "users"."id" FROM "users"WHERE ("users"."email" = 'me@me.com') LIMIT 1 AREL (0.9ms) INSERT INTO "users" ("login", "email", "password", "created_at", "updated_at" , "photo_file_name", "photo_content_type", "photo_file_size") 值 ('meme', 'me@me.com', 'meme', '2013-06-08 12:18:58.686143', '2013-06-08 12:18:58.686143',NULL,NULL,NULL)[回形针]保存附件。com', 'meme', '2013-06-08 12:18:58.686143', '2013-06-08 12:18:58.686143', NULL, NULL, NULL) [回形针] 保存附件。com', 'meme', '2013-06-08 12:18:58.686143', '2013-06-08 12:18:58.686143', NULL, NULL, NULL) [回形针] 保存附件。