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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:30:37+00:00 2026-05-28T06:30:37+00:00

I have a bit of an odd issue. I have a projects controller where

  • 0

I have a bit of an odd issue. I have a projects controller where I am creating a new project related to a company and created by the logged in user (current_user), here is my create action.

def create
  @project = @company.projects.build(params[:project].merge!(:user => current_user))
  #@project.user = current_user
  if @project.save
    #debugger
    flash[:notice] = "Project has been created."
    redirect_to [@company, @project]
  else
    flash[:alert] = "Project has not been created."
    render :action => "new"
  end
end

The above code breaks on the redirect to the project show page with the following error:

undefined method `email’ for nil:NilClass

%b
  Created by
  = @project.user.email # <-- errors, not sure why

So I know everything else is saving except the user who created that project. If I remove the .merge! in my create method and do it in two steps it works perfectly fine, like so:

def create
  @project = @company.projects.build(params[:project])
  @project.user = current_user
  ....

How come using merge! would not work? I would have thought that merging the user into the object would be perfectly fine. What is the right (or preferred) way to go about this?

Thanks

  • 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-28T06:30:38+00:00Added an answer on May 28, 2026 at 6:30 am

    I’ve figured it out. It was a mass assignment issue. I had attr_accessible :title, :description, :account_number, :account_executive in my code, disabled it to allow mass assignment and it worked fine.

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

Sidebar

Related Questions

I have a little bit of an odd issue. When I run this SQL:
I have a bit of an odd issue. I am porting an old, static,
I have a bit of an odd database model for a project - I'm
This is a bit of an odd situation. Here's what's happening. So, we have
This is an odd problem, so I have to provide a bit of background.
I know it sounds a bit odd but I have a string: <img src=image1.gif
We have a bit of an odd setup, which comes from the fact we
I have a bit of an odd use-case for a Ruby Enumerable, it seems.
I'm having a bit of a odd issue with my height of tables. I
I have a bit of an odd problem, and I'm struggling to track down

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.