Hello everyone,
I was having an issue accessing the uploaded file in my model when I passed it with the params hash like:
def create @user = User.new(params[:user]) if @user.save redirect_to( @user ) else @title = "Sign up" render 'new' end end
I thought it would work because it worked for :password and :password confirmation in my model with:
attr_accessor :password, :password_confirmation
Which as I understand gives you setters and getters for the symbols that are passed. So I added:
attr_accessor :password, :password_confirmation, :uploaded_file
And I got errors saying uploaded_file was a nil class
I got it to work by simply creating a function in my model:
def pass_upload( upload ) @profile_picture = upload end
And then in my controller:
def create @user = User.new(params[:user]) @user.pass_upload(params[:user][:profile_picture]) if @user.save redirect_to( @user ) else @title = "Sign up" render 'new' end end
But this does not seem like the best methods I was wondering if any one knew why attr_accessor wouldn't allow easy access to the upload_file class like it did with the more simple variables :password and :password_confirmation.
Thank you