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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:01:16+00:00 2026-06-02T17:01:16+00:00

I get the following error when I try to submit a form in my

  • 0

I get the following error when I try to submit a form in my Rails 3 project. The form is used when 1 user sends a a message to another user, using the Simple Private Messaging plugin.

The way I have set the site up right now, users do not have to sign up or login in order to send a message.

THE ERROR I AM GETTING

NoMethodError in MessagesController#create

undefined method `find_by_login' for #<Class:0x12a374238>

app/controllers/messages_controller.rb:33:in `create'

MESSAGES CONTROLLER

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

MESSAGES>NEW VIEW (This is where Form is being created)

<%= form_for @message, :url => messages_path(:user_id => @user) do |f| %>
<br>
<br />
<br />
<div class="field">
Hello! My name is <%= f.text_field :subject %> and I'm contacting you in response to your ad. I'm interested in learning more so get in touch! Here's my contact details: <%= f.text_field :body %>.
</div>
<button type="submit" class="btn span6 large">Submit</button>
<% 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

USER MIGRATION

class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
  t.string :email
  t.string :salt
  t.timestamps
end
end
end

RAILS CONSOLE OUTPUT ON FINDING USERS BY LOGIN

>> u = User.first
User Load (1.0ms)  SELECT "users".* FROM "users" LIMIT 1
=> nil
>> u.login
NoMethodError: undefined method `login' for nil:NilClass
from /Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/whiny_nil.rb:48:in `method_missing'
from (irb):2
>> 

ROUTES.RB

Mysalary::Application.routes.draw do

resources :users do
 resources :messages
   end

resources :profiles
resources :pages
resources :posts

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

root :to => 'posts#new'

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-02T17:01:18+00:00Added an answer on June 2, 2026 at 5:01 pm

    find_by_attribute (find_by_login in your case) is a dynamic method added by Rails if you have a column called login in your DB table (The users table in your case). Since you’re users table doesn’t contain a login column your User model haven’t a login attribute and haven’t a find_by_login method.

    Since you have an email column try to replace the offending line with this

    @message.recipient = User.find_by_email(params[:message][:to])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get the following error message when I try the following: Dim XL As
When I try to compile this project I get the following error. I would
I get the following error when I try and execute the code down below.
I get the following error when I try to run sample example of Google
I get the following error in the UDK Frontend when I try to make
When I try to I get the following error in SQL Server Management Studio:
When I try to run a routine I get the following error: Error Code:
When I try rake db:migrate, I get the following error: !!! The bundled mysql.rb
When I try rake db:migrate, I get the following error: The bundled mysql.rb driver
When I try to compile Gforth 0.7.0, I get the following error: $ ./configure

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.