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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:26:45+00:00 2026-05-26T12:26:45+00:00

I have model User. And one of controller methods is def view_messages @user =

  • 0

I have model User. And one of controller methods is

 def view_messages
    @user = User.find(params[:id])
    @message=Message.new
    @messages=@user.messages.reverse
  end

Also i have model Message , and one of parametres of this model is user_from:integer

view_messages view have

render :partial => 'messages/message', :collection => @messages

and _message.haml have

= content_tag_for(:li,message) do
  %p
    From:
    =link_to User.find(message.user_from).name,User.find(message.user_from)

it writes an error

Couldn’t find User without an ID

but if i want to print it like

 = content_tag_for(:li,message) do
      %p
        From:
        =message.user_from

it print it ( for exaple it prints 2) , so why it cant find user with id 2 if i have this user? What i am doing wrong?
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-05-26T12:26:45+00:00Added an answer on May 26, 2026 at 12:26 pm

    General issues:

    1. user_from should be user_from_id, by Rails convention

    2. Then you should have a belongs_to relation:

      class Message
        belongs_to :user_from
      end
      

      which will automatically pull the user from the database

    3. Then you can refer to the user as an attribute of Message

      link_to @message.user_from.name, @message.user_from
      

    Check all of the Message records. One of them probably has no user_from, and causes the error.

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

Sidebar

Related Questions

Controllers class ExperiencesController < ApplicationController def create @resume = Resume.find(params[:resume]) @experience = @resume.build_experience(params[:experience]) end
I have two types of users: managers, and employees. I use one User controller
In my Asp.net MVC app, I have two methods on a controller, one for
it's possible to have one entity object (class, e.g. User) for more entity models
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Say I have a model called User that has the following parameters: favorite_color, favorite_animal,
I have a model Foo which have a ForeignKey to the User model. Later,
I have a model that has a ForeignKey to the built-in user model in
I have a user model on which I check to make sure that the
I have a user model that requires the user to change their password every

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.