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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:58:16+00:00 2026-06-17T18:58:16+00:00

I am getting a NoMethodError in ProjectsController#create with the following code: def create @project

  • 0

I am getting a “NoMethodError in ProjectsController#create” with the following code:

def create
  @project = current_user.project.build(params[:project])
  if @project.save
    flash[:success] = "Project created!"
    redirect_to root_url
  end
end

I have tried using @project = current_user.project.create(params[:project]) as well, but I get the same error, albeit for .create.

My Project model looks like this:

class Project < ActiveRecord::Base
  attr_accessible :title,
                  :sub_title,
                  :desc,
                  :category

  validates :user_id, presence: true
  validates :title, presence: true, length: { maximum: 35 }
  validates :category, presence: true

  belongs_to  :user
  ...
end

and my User model looks like this:

class User < ActiveRecord::Base
  attr_accessible :name,
                  :surname,
                  :email,
                  :email_confirmation,
                  :password,
                  :password_confirmation

  has_secure_password

  has_one :project
  ...
end

From what I can tell, this should create a new Project with an association to the user.id and project.user_id. Any ideas why I get the error instead of successful creation?

  • 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-17T18:58:18+00:00Added an answer on June 17, 2026 at 6:58 pm

    For has_one associations you want:

    @project = current_user.build_project(params[:project])
    

    The same pattern is used for create:

    @project = current_user.create_project(params[:project])
    

    If you look at the has_one documentation they list the methods that get created when you declare the association.

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

Sidebar

Related Questions

I'm migrating my refinerycms project to production and i'm now getting the error NoMethodError
I am getting an error running the following method in an after_save callback NoMethodError
Getting the following error when implementing this calendar gem. NoMethodError in Users#show Showing /Users/nelsonkeating/Desktop/ReminDeal/app/views/users/show.html.erb
I'm getting the following error: #<NoMethodError: undefined method `find_it' for #<struct xJob xxxx_id=527>> I
Directly after generating a scaffold I am getting a NoMethodError when trying to create
In my rails project I'm getting the following error when I view /subscription/new :
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
I just installed the plugin for Paperclip and I am getting the following error
I'm a newbie Rails developer who is getting the following error when trying to
I am getting the following error when submitting an update form with nested models

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.