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

I am using rails 3.0.10 and ruby 1.9.2p0 In my rails app I am
I am using mongoid in rails app. rails 3.0.10 ruby 1.9.2p0 When I am
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
This is not a ruby/rails project deploy. I have the following situation and I
I am using Rails 3.0.1, Bundler 1.0.3 and Ruby 1.9.2p0 (2010-08-18 revision 29036). Everything
i am running ruby 1.9.2p0 on rails on windows OS with rubymine 3.1.1. i
I tried configuring log4r with Rails 3.0.4 based on this article: http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/ /Users/toto/.rvm/gems/ruby-1.9.2-p0/gems/log4r-1.1.9/lib/log4r/yamlconfigurator.rb:166:in `sub!':
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
Has anyone used Ruby/Rails with a Sales Logix 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.