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

  • Home
  • SEARCH
  • 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 8896411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:02:34+00:00 2026-06-15T00:02:34+00:00

Say user submits a form (creates new item in his account). Before it goes

  • 0

Say user submits a form (creates new item in his account).

Before it goes to database – I want to do this:

params[:user] => current_user.id
# make a note of who is the owner of the item
# without people seing this or being able to change it themselves
# and only after that to save it to database

What’s the best way to do it?

All I see in controller is this:

def create
    @item = Item.new(params[:item])
    ...
end

And I’m not sure how to change values under params[:item]

(current_user.id is Devise variable)

Tried to do this:

class Item < ActiveRecord::Base
    before_save :set_user

    protected

    def set_user
        self.user = current_user.id unless self.user
    end

end

And got an error:

undefined local variable or method `current_user'
  • 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-15T00:02:35+00:00Added an answer on June 15, 2026 at 12:02 am

    It should be as simple as:

    def create
        @item = Item.new(params[:item])
        @item.user = current_user
        #...
    end
    

    You’re getting an undefined local variable or method current_user error as current_user is not available in the model context, only controller and views.

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

Sidebar

Related Questions

Let's say I've got a simple form (but it's fairly long). This form submits
Let's say user A follows user B, and B follows A. I want to
If I have an object say @user and I want to render only certain
how should I store user data in asp.net mvc? Let's say a user want
I am new to backbone.js , and have a query. Say my user is
I have created a form where the user can search the database, and the
Lets say you had a simple form to create a new article object in
If a website user submits an HTML form with: (1) a post method; (2)
So I have a subscription form where a user is simultaneously creating a new
Ok, So I have a form that is on page 'index.html'. The user submits

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.