好吧,所以我遇到了在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