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 3623884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:26:19+00:00 2026-05-18T23:26:19+00:00

Rails 3.0.3 ruby 1.9.2p0 The Problem: I have a Users table which has many

  • 0

Rails 3.0.3
ruby 1.9.2p0

The Problem:

I have a Users table which has many items, the item(s) in turn therefore belongs to the Users.

In my model item.rb i attempt to save the item along with the value for the user.id so i have:

self.User_ID = @user.id

this however give me the error

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

this is causing some confusion that it can’t find this as in the show.html.erb that ‘wraps’ this page <%= @user.id %> displays the correct ID on the page

Many thanks in advance

** EDIT **
The Shorten action is the action upon which i want to parameter to be passed

class ItemsController < ApplicationController

  def redirect
    @item = Item.find_by_shortened(params[:shortened])
    if @item
      #redirect_to @item.original
      redirect_to @item.original
    else
      redirect_to :shorten
    end
  end

  def shorten
    @host = request.host_with_port
    @user = 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-05-18T23:26:19+00:00Added an answer on May 18, 2026 at 11:26 pm

    You need to load the @user model in every action that will require access to it. Having it render properly in the show action will not guarantee it is loaded in the update action.

    Usually you need to have something like this in your controller:

    class UsersController < ApplicationController
      before_filter :load_user, :except => [ :index, :new, :create ]
    
      # ...
    
    protected
      def load_user
        @user = User.find(params[:user_id] || params[:id])
      rescue ActiveRecord::RecordNotFound
        render(:text => 'Record not found')
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone used Ruby/Rails with a Sales Logix database?
After our Ruby on Rails application has run for a while, it starts throwing
Ruby on Rails has magic timestamping fields that are automatically updated when a record
Ruby on Rails has a lot of ways to generate JavaScript. Particularly when it
I have been creating a website with Ruby on Rails, and will be hosting
My environment: Mac OSX 10.6 Snow Leopard Ruby 1.9.2p0 Rails 3.0.0 thinking-sphinx (2.0.0.rc1) Sphinx
I have a Rails Model: ruby-1.9.2-p0 > NavItem => NavItem(id: integer, item_identifier: string, description:
I am using Rails 3.0.1, Bundler 1.0.3 and Ruby 1.9.2p0 (2010-08-18 revision 29036). Everything
$ ruby -v ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.3.0] $ rails s => Booting
Within Ruby on Rails applications database.yml is a plain text file that stores database

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.