Search code examples
ruby-on-railsrails-activerecordupdate-attribute

update user model from some other control


I have a user model. i want to update a column of user from some other controller, that is not related to user. following is my code to update value.

   def update
        @admin=current_user
        if @admin.update_attribute(:allow, params[:user][:allow])
          flash[:success] = "Feature updated"
          redirect_to '/recalls'
        else
            flash[:success]=@admin.errors.full_messages
        end
   end

the problem is allow value in db gets updated. i can verify it from my rails console. but while redirecting to /recalls, it log out and redirects to Login. i don't know what wrong i have done. plz let me know. Thanks in Advance


Solution

  • from the comment of Gopal Rathore in original post. I added sign_in method as follows to solve the problem

       def update
            @admin=current_user
            if @admin.update_attribute(:allow, params[:user][:allow])
              sign_in
              flash[:success] = "Feature updated"
              redirect_to '/recalls'
            else
                flash[:success]=@admin.errors.full_messages
            end
       end