Develop controller registration + clip

I am trying to override the registration registration controller so that the user can upload his avatar along with changing other data and trim the userpic after loading.

I added all the necessary paperclip attributes of the user, created an idea of ​​the lessons, and my registration controller looks like this:

class RegistrationsController < Devise::RegistrationsController def update if params[resource_name][:avatar].blank? super else @user=resource respond_to do |format| if resource.update_attributes(params[resource_name]) flash[:notice]='Avatar successfully uploaded.' format.html { render :action => 'crop' } format.xml { head :ok } else format.html { render :action => "editpicture" } format.xml { render :xml => @demotivator.errors, :status => :unprocessable_entity } end end end end end 

but when I submit the form with the image, nothing happens, except that firefox shows "loading ..." forever! absolutely no updates in the development log ..: (

can someone tell me what i can do wrong?

ps. user editing form is as follows:

 <%= form_for(@user, :url => registration_path(@user), :html => {:id => "userpic_form", :method => :put, :multipart => true}) do |f| %> <p class="box1_po">Current password: <%= f.password_field :current_password %></p> <p class="box1_po">Please select your user picture: <%= f.file_field :avatar %> </p> <input type="submit" class="usubmit"><%= link_to "UPLOAD", "#", :onclick => "$('#userpic_form').submit();"%> <% end %> 
+7
source share
3 answers

I just needed to add

 attr_accessible :avatar 

in the user model, and he began to work normally

+7
source

If you are using Rails 4 , add the following to the RegistrationsController

 # get devise to recognize the custom fields of the user model before_filter :configure_permitted_parameters, if: :devise_controller? protected def configure_permitted_parameters devise_parameter_sanitizer.for(:account_update) do |u| u.permit(:avatar, :email, :password, :password_confirmation) end end 
+2
source
  • Make sure the parameter is enabled in the controller as shown below: `

     def configure_permitted_parameters devise_parameter_sanitizer.permit(:account_update, keys: [:firstname, :lastname, :username, :password, :email, :bio, :avatar,:password_confirmation, :current_password ]) end` 
  • Make sure you add this tag:: :html => { :multipart => true } to the form:

    <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }, :html => { :multipart => true }) do |f| %>

0
source

All Articles