Search code examples
ruby-on-railsrubydevise

localhost redirected you too many times ruby on rails


I'm using devise/Ruby on Rails and when I try to open my localhost I get the following infinite loop, and have no idea why since the only change I've made was creating seeds using the Faker gem, and creating a show view for when the user logs in.

At first I thought it was something wrong with my if/else statement in my controller, since when I reseed the data, there's no current_user signed in and it should take me to the new user registration path created through devise, but was lost as to why it repeats itself..

Any and all help would be greatly appreciated!

Below is terminal:

Started GET "/users/sign_in" for 127.0.0.1 at 2017-12-30 13:53:58 -0800
Processing by UsersController#show as HTML
  Parameters: {"id"=>"sign_in"}
Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)

UsersController

class UsersController < ApplicationController

before_action :authenticate_user!

  def show
    if current_user.present?
      @user = current_user
      @item = Item.new
      @items = @user.items
    else
      redirect_to new_user_registration_path
    end  
  end
end

Users#show

<h2> Your to-do list</h2>


  <div class="col-md-8">
    <div class='items'>
      <%= render partial: "items/item", local: { item: @item} %>
    </div>
  </div>
  <div class="col-md-8">
    <div class='new-item'>
      <%= render partial: "items/form", local: { item: @item } %>
    </div>
  </div>

Routes:

Rails.application.routes.draw do
  get 'welcome/index'

  get 'welcome/about'

  root 'users#show'

  resources :users do
    resources :items, only: [:new, :create, :index]
  end


  devise_for :users
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

Solution

  • Was able to figure out the root issue, being order of placement of code in routes.rb.