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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:55:37+00:00 2026-06-02T02:55:37+00:00

I am trying to add a link to my Posts>Index page which lets people

  • 0

I am trying to add a link to my Posts>Index page which lets people send direct message (using Simple Private Messaging) to the creator of the Post.

Currently I have a link to /messages/new to do this, but this is not working – Iget the following error in my app when I try to access /messages/new.

I want to replace the link to /messages/new (in POSTS>INDEX file below) with something better that works. Let me know if you have any thoughts!!

**NoMethodError in Messages#new**

Showing /Users/fkhalid2008/loand/app/views/messages/new.html.erb where line #1 raised:

undefined method `user_messages_path' for #<#<Class:0x12a77f198>:0x12a76dce0>

Extracted source (around line #1):

1: <% form_for @message, :url => user_messages_path(@user) do |f| %>
2:   <p>
3:     To:<br />
4:      <%= f.text_field :to %>

ADDITIONAL INFORMATION: The app itself is like Gumtree.com, where Users come and create Posts (e.g. selling my car), and people respond my sending them Messages (through the Simple Pvt Messages plugin).

Thanks!

Faisal

MESSAGES>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 %>

MESSAGE MODEL

class Message < ActiveRecord::Base

is_private_message

attr_accessor :to

end

ROUTES.RB

Mysalary::Application.routes.draw do

resources :messages do
   collection do
     post :delete_selected
     end
   end

resources :users
resources :profiles
resources :pages
resources :posts

get "pages/home"
get "pages/about"
get "pages/legal"
get "pages/feedback"

root :to => 'posts#new'

end

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.first
end
end

POSTS>INDEX VIEW

<table class="table table-striped">
<tbody>
<% @posts.each do |post| %>
<tr>
<td>I am a <%= post.title %> getting married in <%= post.job %> in <%= post.location %>, and looking for a <%= post.salary %>. My budget is <%= post.salary %>.</td>
<td> <button class="btn" data-toggle="button" onClick="javascript:location.href = '/messages/new';" />Contact</button></td>
<td><%= time_ago_in_words(post.created_at) %> ago.</td>
<!--/. 
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
-->
</tr>
<% end %>
</tbody>
</table>
  • 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-02T02:55:38+00:00Added an answer on June 2, 2026 at 2:55 am

    you routes.rb doesn’t define path user_messages_path, it’s simple 🙂

    If you want nested restful routes, you need something like

    resources :users do
      resources :messages
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am trying to add a link besides the Edit | Delete links in wordpress
Hi in my app when i was trying to add a link in textview
I am trying to add arrow to accordion main title link if it has
I'm trying to add an arrow image to my link and have it positioned
I am trying to hide my Add friend link if - current_user and @user
I'm trying to add Facebook's comment count to my website. I'm using the Facebook
I m trying to add the first link from the post content to a
I am trying to write a simple Javascript snippet into a Codeigniter link. I
I'm trying to list the post titles using a regular wp_query, just to add
I'm trying to add a link to a basic MvcScaffolding project that outputs all

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.