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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:05:44+00:00 2026-06-02T07:05:44+00:00

I am working on a website like Gumtree.com, where Users create Posts, highlighting their

  • 0

I am working on a website like Gumtree.com, where Users create Posts, highlighting their various needs (e.g. I need a photographer on day X).

Having some trouble with the Messaging functionality. I am using the Simple Private Messaging plugin.

Problem is in the form that Users fill out to send a message / respond to a post. I get the following error when I try to access /messages/new:

ActiveRecord::RecordNotFound in MessagesController#new
Couldn't find User without an ID

Attaching my models below – grateful for any advice!

Thanks,

Faisal

MESSAGES CONTROLLER

class MessagesController < ApplicationController

before_filter :set_user

def index
if params[:mailbox] == "sent"
  @messages = @user.sent_messages
else
  @messages = @user.received_messages
end
end

def show
@message = Message.read_message(params[:id], current_user)
end

def new
@message = Message.new

if params[:reply_to]
  @reply_to = @user.received_messages.find(params[:reply_to])
  unless @reply_to.nil?
    @message.to = @reply_to.sender.login
    @message.subject = "Re: #{@reply_to.subject}"
    @message.body = "\n\n*Original message*\n\n #{@reply_to.body}"
  end
end
end

def create
@message = Message.new(params[:message])
@message.sender = @user
@message.recipient = User.find_by_login(params[:message][:to])

if @message.save
  flash[:notice] = "Message sent"
  redirect_to user_messages_path(@user)
else
  render :action => :new
end
end

def delete_selected
if request.post?
  if params[:delete]
    params[:delete].each { |id|
      @message = Message.find(:first, :conditions => ["messages.id = ? AND (sender_id = ? OR recipient_id = ?)", id, @user, @user])
      @message.mark_deleted(@user) unless @message.nil?
    }
    flash[:notice] = "Messages deleted"
  end
  redirect_to :back
end
end

private
def set_user
  @user = User.find(params[:user_id])
end
end

MESSAGE MODEL

class Message < ActiveRecord::Base

is_private_message

attr_accessor :to

end

USER MODEL

class User < ActiveRecord::Base

has_many :posts  
has_one :profile
has_private_messages

attr_accessible :email

validates_presence_of :email
validates_uniqueness_of :email, :message =>"Hmm, that email's already taken"
validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i, :message => "Hi! Please use a valid email"


end

MESSAGE>NEW VIEW

<% form_for @message, :url => user_messages_path(@user) do |f| %>
<p>
To:<br />
    <%= f.text_field :to %>
    <%= error_message_on @message, :to %>
</p>
<p>
Subject:<br />
<%= f.text_field :subject %>
<%= error_message_on @message, :subject %>
</p>
<p>
  Message<br />
  <%= f.text_area :body %>
        <%= error_message_on @message, :body %>
</p>
<p>
  <%= submit_tag "Send" %>
</p>
<% end %>
  • 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-02T07:05:45+00:00Added an answer on June 2, 2026 at 7:05 am

    Are you sure that your page for new messages receives :user_id in it’s params? Even if it is true, I doubt that this is was your intention because anyone can pretend to be another user by just passing another :user_id.

    So your line in the bottom:

    @user = User.find(params[:user_id]) # I think it's the cause of your error -- no :user_id is passed
    

    seems like has to be:

    @user = User.find(session[:user_id])
    

    I suppose you’ve heard about sessions.

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

Sidebar

Related Questions

I'm working on website with lyrics from all kind of bands, much like Lyrics.com
I'm working on a website that allows users to create an account. One of
I'm working on the avatar upload on my website and would like for users
I am working on a website and would like for my users to be
I'm working on a website that will use features of social networking (like facebook
I'm working on a website for a client, and I would like to customize
I'm working on a mobile-friendly website using jQuery Mobile but would like to do
I'm working on a website that will be using Facebook Connect to authenticate users.
I'm building an IMDB.com like website using PHP/jQuery and a MVC approach (no OOP).
I am working on a mobile website and would like to test it using

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.