Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## profiles_controller.rb
- # PUT /profiles/1
- # PUT /profiles/1.xml
- def update
- @profile = Profile.find(@user)
- respond_to do |format|
- if @profile.update_attributes(params[:profile])
- @params = params[:form]
- if @params == "avatar"
- format.js do
- responds_to_parent do
- render :update do |page|
- page["avatar_form"].toggle
- page["avatar"].replace :partial => 'profiles/avatar'
- end
- end
- end
- else
- format.js do
- render :update do |page|
- page["#{@params}_form"].toggle
- page["#{@params}"].replace :partial => @params
- end
- end
- end
- format.html { render :action => "edit" }
- format.xml { render :xml => @profile.errors, :status => :unprocessable_entity }
- end
- end
- end
- ##form
- <div id="avatar_form">
- <% remote_form_for :profile,
- :url => formatted_user_profile_path(@user, :js, :form => "avatar"),
- :html => {
- :multipart => true,
- :target => "upload_frame",
- :method => :put
- } do |f| %>
- <%= f.file_field :avatar %>
- <%= submit_tag "Upload" %>
- <% end %>
- <iframe id="upload_frame" name="upload_frame" style="width:1px;height:1px;border:0px" src="about:blank"></iframe>
- </div>
Add Comment
Please, Sign In to add comment