0

I have an Author model on my site where users can upload an avatar image of themselves. The initial sign up/image upload works but when I try to change the image using the author#edit action after the fact I get this error:

param not found: author
params.require(:author).permit(:first_name, :last_name, :email, :password, :password_confirmation, :image)

author.rb

class Author < ActiveRecord::Base
  before_create { generate_token(:auth_token) }
  has_secure_password
  before_save { email.downcase! }

  mount_uploader :image, ImageUploader

    has_many :novels

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, 
    presence: true, 
    format: { with: VALID_EMAIL_REGEX, message: 'Invalid email address' }, 
    uniqueness: { case_sensitive: false }

  validates :first_name, presence: true
  validates :last_name, presence: true
  validates :password, presence: true, confirmation: true, on: :create

  def send_password_reset
    generate_token(:password_reset_token)
    self.password_reset_sent_at = Time.zone.now
    save!
    PasswordResetMailer.password_reset(self).deliver
  end

  def send_activation
    AuthorMailer.activate(self).deliver
  end

  def generate_token(column)
    self[column] = SecureRandom.urlsafe_base64
  end

end

authors_controller.rb

  def edit
    @author = Author.find(params[:id])
  end

  def update 
    if @author.update(author_params)
      flash[:notice] = "Profile has been updated."
      redirect_to @author
    else
      flash[:alert] = "Profile has not been updated."
      render :edit
    end
  end

  private

    def author_params
      params.require(:author).permit(:first_name, :last_name, :email, :password, :password_confirmation, :image)
    end

edit.slim

- provide(:title, 'Edit Author')
.row
  .col-lg-4.col-lg-offset-1
    h1 Edit Your Profile
hr
  .row
    .col-xs-6.col-lg-4
      = simple_form_for @author, as: 'user_horizontal', html: { class: 'form-horizontal' }, wrapper: :horizontal_form, wrapper_mappings: { check_boxes: :horizontal_radio_and_checkboxes, radio_buttons: :horizontal_radio_and_checkboxes, file: :horizontal_file_input, boolean: :horizontal_boolean } do |f|
        = image_tag @author.image_url, class: "avatar"
        = f.input :image, as: :file
        = f.submit "Submit", class: "btn btn-small btn-default"
Mike Glaz
  • 5,352
  • 8
  • 46
  • 73
  • Check this out http://stackoverflow.com/questions/17937112/rails-4-strong-parameters-param-not-found-error-with-carrierwave – maximus ツ Aug 03 '14 at 18:49
  • Your core problem is that the `:author` param is not getting sent, as the error message indicates. Could you post the server log for the failed request? – BrendanDean Aug 04 '14 at 02:23

0 Answers0