Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8732131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:52+00:00 2026-06-13T09:22:52+00:00

my plan is to use Devise to register a user and giving him the

  • 0

my plan is to use Devise to register a user and giving him the opportunity to upload a picture (paperclip) while registering.
So I have users and users_pictures where user has_many :users_pictures.

I modified the usermodel like this:

after_create :create_users_picture

def create_users_picture
    user_id = User.last.user_id
    UsersPicture.create!(:user_id => user_id)
end

This was just a test to see if it’s working and it actually does.
But now I need to get the fileinformation from the paperclip upload.
I already inserted the file_field to the users_view and the data is submitted correctly.
Then I tried something like:

def create_users_picture
    @users_picture = UsersPicture.new(@user)
    @users_picture.save
end

Because I thought that @user contains all necessary data … but then I get:

Parameters: {"user"=>{"user_firstname"=>"merrr", "password_confirmation"=>"[FILTERED]", "photo"=>#<ActionDispatch::Http::UploadedFile:0xe54abbb4 @content_type="image/jpeg", @tempfile=#<File:/tmp/RackMultipart20121023-7937-1tbp5v7-0>, @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"rh.jpeg\"\r\nContent-Type: image/jpeg\r\n", @original_filename="rh.jpeg">, "user_lastname"=>"merrr", "email"=>"merrr@asd.de", "password"=>"[FILTERED]", "user_login"=>"merrr"}, "commit"=>"Sign up", "authenticity_token"=>"GRzc3Wx5mJJwBL32qjpMi24sCZdoWdRZgucldmk7Bmo=", "utf8"=>"✓"}
Completed 500 Internal Server Error in 347ms

ActiveRecord::StatementInvalid (Mysql2::Error: Column 'user_id' cannot be null: INSERT INTO `users_pictures` (`photo_content_type`, `photo_file_name`, `photo_file_size`, `user_id`) VALUES (NULL, NULL, NULL, NULL)):
app/models/user.rb:36:in `create_user_profile'

So I can get the user_id by using User.last.user_id but how can I get the fileinformation from the picture upload ?
Do I need to get access to the POST data ? And if so, how do I do that ?
Additionally, I need to check if the user eventually tried to upload a picture … because he does not have to.
That could be done by simply checking if there was some kind of picture data send by the form ?
Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:22:53+00:00Added an answer on June 13, 2026 at 9:22 am

    I don’t think that you actually understand that you are doing))

    Good way to do that you want is to use nested attributes for association.
    But i don’t thin it will help you, so first of all you have to read everything here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two different installations on the same server that I plan to use
Using this question and answer ( Use both Account and User tables with Devise
we plan to use TIBCO EMS queues and TIBCO BW listeners on those queues
If I do a query (I plan to use SDS.P) against the global catalog,
Need an async I/O Processing Plan to use async I/O through aio* calls on
I am developing a web app for which I plan to use InnoDB. However
I'm looking for a a mouseover sound script (for button). I plan to use
I'm working on a document storage. Therefore I plan to use SqlServer 2012 with
I am using mod_perl for my web application. Currently, I plan to use a
We use scrum technique to plan for short development lifecycle. It is very common

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.