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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:41:01+00:00 2026-06-16T05:41:01+00:00

I have three resources – users , lists and items . I just nested

  • 0

I have three resources – users, lists and items. I just nested lists under users and updated my links accordingly, but I am getting two errors from rspec which are a complete mystery to me. Everything worked before I nested the routes.

I’m a total newbie to rails and any help is thus much appreciated!

  1) Authentication authorization for non-signed-in users in the Lists controller submitting to the destroy action 
     Failure/Error: before { delete user_list_path(user, FactoryGirl.create(:list)) }
     ActiveRecord::RecordInvalid:
       Validation failed: Email has already been taken
     # ./spec/requests/authentication_pages_spec.rb:84:in `block (6 levels) in <top (required)>'

  2) User pages profile page 
     Failure/Error: before { visit user_path(user) }
     ActionView::Template::Error:
       No route matches {:action=>"show", :controller=>"users", :id=>nil}
     # ./app/views/shared/_user_info.html.erb:1:in `_app_views_shared__user_info_html_erb__1836116684083464018_70145329446120'
     # ./app/views/users/show.html.erb:4:in `_app_views_users_show_html_erb___902249955135429148_70145329432180'
     # ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'

routes.rb

MyApp::Application.routes.draw do
  resources :users do
    resources :lists, only: [:show, :create, :destroy]
  end
  resources :items, only: [:show, :create, :destroy]
  resources :sessions, only: [:new, :create, :destroy]

user.rb

class User < ActiveRecord::Base
  attr_accessible :name, :email, :password, :password_confirmation
  has_secure_password
  has_many :lists, dependent: :destroy
  has_many :items, through: :lists

list.rb

class List < ActiveRecord::Base
  attr_accessible :name
  belongs_to :user
  has_many :items, dependent: :destroy

item.rb

class Item < ActiveRecord::Base
  attr_accessible :link, :list_id, :title
  belongs_to :list

UPDATE

user_pages_spec.rb

require 'spec_helper'

describe "User pages" do

  subject { page }

  describe "profile page" do
    let(:user) { FactoryGirl.create(:user) }
    let!(:l1) { FactoryGirl.create(:list, user: user, name: "Foo") }
    let!(:l2) { FactoryGirl.create(:list, user: user, name: "Bar") }

    before { visit user_path(user) }

    it { should have_selector('h1',    text: user.name) }
    it { should have_selector('title', text: user.name) }

    describe "lists" do
      it { should have_content(l1.name) }
      it { should have_content(l2.name) }
      it { should have_content(user.lists.count) }
    end
  end

  describe "lists page" do
    let(:user) { FactoryGirl.create(:user) }
    let!(:l1) { FactoryGirl.create(:list, user: user, name: "Foo") }
    let!(:i1) { FactoryGirl.create(:item, list: l1, title: "Shirt") }

    before { visit user_list_path(user, l1) }

    it { should have_content(i1.title) }
    it { should have_content(l1.items.count) }
  end
...

UPDATE 2

users_contoller.rb

class UsersController < ApplicationController
  before_filter :signed_in_user, only: [:edit, :update]
  before_filter :correct_user,   only: [:edit, :update]

  def show
    @user = User.find(params[:id])
    @lists = @user.lists
    @list = current_user.lists.build if signed_in?
  end

  def new
    @user = User.new
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to Wishlistt!"
      redirect_to @user
    else
      render 'new'
    end
  end

  def edit
  end

  def update
    if @user.update_attributes(params[:user])
      flash[:success] = "Profile updated"
      sign_in @user
      redirect_to @user
    else
      render 'edit'
    end
  end

  private

    def correct_user
      @user = User.find(params[:id])
      redirect_to(root_path) unless current_user?(@user)
    end
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-16T05:41:02+00:00Added an answer on June 16, 2026 at 5:41 am

    Your first error is telling you that the user you are creating is invalid because a user with that email has already been created. (Failing an email uniqueness validation ) You can get around this by changing your user factory to sequence the email so that every record is unique like so:

    sequence(:email) { |n| "User#{n}@example.com"}
    

    The second test fails for this exact same reason. Since your user record is nil, you are essentially trying to grab a non-existant record from your database. It is telling you that in the line:

    No route matches {:action=>"show", :controller=>"users", :id=>nil}
    

    By having the user = nil, the following is happening in your show action:

    your implementation will look something like this:
    #####
    @user = User.find(params[:id])
    #####
    

    since params[:id] = nil, you get

    User.find(nil)
    

    Which will fail since there is no user record with an id of nil. The rest of your implementation should be fine.

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

Sidebar

Related Questions

I need some help with nested resource actions. I have three nested resources: Jobs,
i have three lists with the same number of elements in each other, i
I'm having a strange situation here.. I have three links which are loading content
I have three tree view controls which house different (but mostly similar data), as
I have three resources: @RequestMapping(value = sample, method = RequestMethod.GET, headers = Accept=text/html) public
I'm starting a new project and I have maybe three resources defined. Not a
I have three resources: Jobs, Questions and Answers. The relationships are: Job has many
I have a nested model resources :customer do resources :readings end Customers model has
I have three models, users, reports, and receipts. Users have many reports, and reports
I have an application that differs for different languages by resources. Is there a

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.