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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:15:56+00:00 2026-06-02T10:15:56+00:00

I am going through the Agile Web tutorial with some slight changes. When I

  • 0

I am going through the Agile Web tutorial with some slight changes. When I run functional tests in Rails 3.2, I am getting the following error:

test_should_get_new(OrdersControllerTest):
ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: cart, deal

Here is the orders_controller_test.rb code:

test "should get new" do
  cart = Cart.create
  session[:cart_id] = cart.id
  LineItem.create(cart: cart, deal: deals(:one))

  get :new
  assert_response :success
end

Here is the orders fixtures:

one:
  name: MyString
  address: MyText
  email: MyString
  pay_type: Check

Here is the line items fixtures:

one:
  deal: one
  order: one

Here is the deals fixture:

one:
  title: MyString
  description: MyText
  image_url: MyString
  price: 9.99

Here is the order controller code:

def new
  @cart = current_cart
  if @cart.line_items.empty?
    redirect_to store_url, notice: "Your cart is empty"
    return
  end

  @order = Order.new

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @order }
  end
end

I tried using FactoryGirl but still got the same error message. Here is the code:

test "should get new" do
  cart = FactoryGirl.build(:cart)
  session[:cart_id] = cart.id
  LineItem.create(cart: cart, deal: deals(:one))

  get :new
  assert_response :success
end

And the FactoryGirl code:

FactoryGirl.define do  
  factory :cart do
  end
end

For FactoryGirl I also tried ‘create’ instead of ‘build’ and got the same error message.

Although I could turn off the mass assignment error in config, I would rather not since I prefer to test properly.

Any suggestions please?

  • 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-02T10:16:09+00:00Added an answer on June 2, 2026 at 10:16 am

    Instead of LineItem.create(cart: cart, deal: deals(:one)) try

    item = LineItem.create
    item.cart = cart
    item.deal = deals(:one)
    

    or in your LineItem model, add:

    attr_accessible :cart, :deal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going through Agile Web Development with Rails and I'm having some trouble with
I'm going through DHH's Agile Web Development with Rails for Rails 3.1. In chapter
Going through Lynda's 2010 tutorial on rails and have been stuck on migration for
Going through the SproutCore Getting started tutorial and have a problem. Inside the Todos.todoListController
While going through a Zend tutorial , I came across the following statement: Note
While Going through the java tutorial on sun site, I see following piece of
After going through some examples on the web I realize that there is a
I had a quick question while going though the Agile Web Development with Rails
Going through this tutorial https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC it is mentioned that to set up a call
While going through Ruby On Rails Tutorial by Michael Hartl,in the section where the

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.