Routing Error - undefined local variable or method `only' for UsersController:Class

Grace Saint Source

Keep receiving this error message when I sign up and log in to a website of mine. I can send you my routes file and application file. But, the sign out works fine when I backspace the URL to one with no backslashes and am able to access the components of the site that are needed when you sign in.

Here's my routes file: get 'sessions/new'

get 'users/new'

resources :pets
resources :users

get 'controller1/home'

get 'controller1/FAQ'

get 'controller1/display'

get 'controller1/calendar'

root 'controller1#home'

get '/signup', to:   'users#new'

get '/login', to: 'sessions#new'

post '/login', to: 'sessions#create'

delete '/logout', to: 'sessions#destroy'

Here's my users controller file:

  class UsersController < ApplicationController
  before_action :set_user, only: [:show, :edit, :update, :destroy]
 before_action :correct_user, only[:edit, :update]
  before_action :admin_user, only: :destroy

   # GET /users
  # GET /users.json
   def index
    @users = User.all
    end

 # GET /users/1
 # GET /users/1.json
 def show
  @user = User.find(params[:id])
 end

 # GET /users/new
  def new
  @user = User.new
   end


 def logged_in_user
   if logged_in?
  true
  else
  false
  flash[:alert] = "Not logged in, you need to follow log in rules"
  redirect_to login_url
   end
 end

 def correct_user
  @user = User.find(params[:id])
 redirect_to(root_url) unless current_user?(@user)
 end


 # GET /users/1/edit
  def edit
   @user = User.find(params[:id])
   end

  # POST /users
  # POST /users.json
  def create
   @user = User.new(user_params)

   respond_to do |format|
    if @user.save
    log_in @user
    format.html { redirect_to @user, notice: 'User was successfully created.'           }
    format.json { render :show, status: :created, location: @user }
  else
    format.html { render :new }
    format.json { render json: @user.errors, status: :unprocessable_entity }
  end
end

end

# PATCH/PUT /users/1 # PATCH/PUT /users/1.json def update respond_to do |format| if @user.update(user_params) format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { render :show, status: :ok, location: @user } else format.html { render :edit } format.json { render json: @user.errors, status: :unprocessable_entity } end end end

# DELETE /users/1 # DELETE /users/1.json def destroy @user.destroy respond_to do |format| format.html { redirect_to users_url, notice: 'User was successfully destroyed.' } format.json { head :no_content } end end

  private
   # Use callbacks to share common setup or constraints between actions.
   def set_user
  @user = User.find(params[:id])
   end

# Never trust parameters from the scary internet, only allow the white list    through.
def user_params
  params.require(:user).permit(:name, :email, :password,        :password_confirmation)
end

   def admin_user
  redirect_to(root_url) unless current_user.admin?
   end 
 end

Here's my sessions controller file:

class SessionsController < ApplicationController
def new
end

 def create
user = User.find_by(email: params[:session][:email].downcase)
if user && user.authenticate(params[:session][:password])
  log_in user
  redirect_to user
else
  flash.now[:danger] = 'Invalid email/password combination'
  render 'new'
  end
   end

  def destroy
  log_out
  redirect_to root_url
   end

   end

enter image description here

Thanks!!

ruby-on-rails

Answers

comments powered by Disqus