Electric Skeleton Electric Skeleton - 4 months ago 13
Ruby Question

uninitialized constant UController::User_param

I am making a basic account setup and to try to learn how the database stuff works. I have been running into this error constantly, and I have no idea how to make it disappear. I have my stuff named as U, so the URL will be easier to type a username like Reddit has it

example.com/u/username


The Error is
uninitialized constant UController::User_param


It highlights this code:
@user = U.new(User_param)


Controller:

class UController < ApplicationController
def index
@users = U.all
end

def show
end

def create
@user = U.new(User_param)

if @user.save
redirect_to :action => 'list'
else
@user = U.all
render :action => 'new'
end
end

def User_param
params.require(:Us).permit(:id, :email, :password, :created_at, :updated_at)
end

def new
@user = U.new
end

def edit
end
end


Routes:
resources :u


U Model:

class U < ActiveRecord::Base
end

Answer

In Rails you don't capitalize methods, only constants and classes. change User_param to user_params along with the method and that should work. I made params plural since it is clearer and easier to understand

Also, change the user_param method to this:

def user_params
  params.require(:u).permit(:id, :email, :password, :created_at, :updated_at)
end

The .require(:u) doesn't need to be plural as you had it.