好吧,所以我遇到了在rails中执行多个表单的问题。这里是低于Rails Multiform结构似乎有点关闭
型号代码
class Profile < ActiveRecord::Base
belongs_to :user
has_attached_file :avatar, :styles => { :medium => "134x137>", :thumb => "111x111>", :tiny => "32x38>" }
validates_attachment_content_type :avatar, :content_type => ['image/pjpeg','image/jpeg', 'image/x-png', 'image/png', 'image/gif']
class User < ActiveRecord::Base
has_one :profile, :dependent => :destroy
档案控制器
def edit
@user = User.find(params[:id])
@profile = @user.profile
end
配置文件,编辑,查看
<% form_for @user do |f| %>
<%= f.text_field :first_name %>
<%= f.text_field :last_name %>
<%= f.text_field :email %>
<%= f.password_field :password %>
<%= f.password_field :password_confirmation %>
<input id="send_update" name="send" type="submit" value="Update" />
<% end %>
<% form_for @profile , :html => { :multipart => true } do |f| %>
<%= render :partial => 'form', :locals => {:f => f, :profile => @profile, :title => 'Edit Profile'} %>
<%= submit_tag 'Update', :style => 'text_align:right'%>
<% end %>
档案_form部分
<label>Upload Avatar</label>
<tr><%= f.file_field :avatar %></tr>
所以基本上我在编辑视图两种形式,当我点击第二个更新更新化身,我去给用户的更新,我得到这个闪存错误“抱歉,出事了”
def update
@user = User.find(params[:id])
current_email = @user.email
if @user.update_attributes(params[:user])
UserMailer.deliver_email_changed (@user) if email_changed?(current_email, @user.email)
flash[:notice] = "<h1>Account updated!</h1>"
redirect_to edit_user_path(@user)
else
flash.now[:error] = "Sorry, something went wrong"
render :action => :edit
end
end
我的问题是这样
- 有没有更好的这种结构的方式,所以也许我有一种形式?
- 为什么现在不存储和什么导致问题?
错误是密码不能为空,但我只是更新头像 – Trace 2010-09-01 13:41:37