Rails: param is missing or the value is empty: admin
I finally figured it out after careful examination of my logs.
Here's how I solved it:
I examined the request parameters of the create
action and I realized that it was of this format:
{"authenticity_token"=>"qJWlHz7Z5myTH3dwNIjjSOzRDY7JN+LoovaG+8dMBnGFRWImJKlWp8cgF7kwTqJXIxqU2fGVkqW9nhOAJ8vFIg==",
"user_admin"=>{"email"=>"promise@gmail.com", "password"=>"[FILTERED]", "role"=>""},
"commit"=>"Create Admin"}
So the request parameters have a hash key of user_admin
with values email
, password
and role
, whereas I was passing the admin
hash key in my admins_controller
.
All I had to do was to modify the admins_params
private method in my admins_controller
:
From this:
def admin_params
params.require(:admin).permit(:email, :password, :role)
end
To this:
def admin_params
params.require(:user_admin).permit(:email, :password, :role)
end
and that solved the issue.
If you have such an issue, always endeavour to inspect your request parameters in your logs or your application trace. That will give you a lot of information that will help you to resolve the issue.
That's all.
I hope this helps
param is missing or the value is empty: name -what exact value to put in require
Just make following changes in your controller,
def user_params
params.require(:user_crud).permit(:name, :email)
end
As your params
contains form inputs under user_crud
key.
param is missing or the value is empty: activity Rails 4
Controller
def create
@todo = Todo.create(todo_params)
respond_to do |format|
if @todo.save
format.html { redirect_to location_path, notice: 'Todo was successfully created.' }
else
format.html { render :new }
}
end
end
end
Params
def todo_params
params.require(:todo).permit(:name, :activity)
end
param is missing or the value is empty: message
Error comes from params.require(:message)
because your incoming params
does not contain :message
key (it has "/messages"
).
This originates in your view - you pass messages_path
(which is "/messages"
) in place of field name/model to form_for
. Try:
form_for :message, url: messages_path do |f|
...
ParameterMissing - param is missing or the value is empty: user
require
ensures that a parameter is present. If it's present, returns the parameter at the given key, otherwise raises an ActionController::ParameterMissing error
.
You are requiring user
parameter but it's missing from the params.
To get this you have many ways.
Method 1:
Removing require should do the trick.
params.permit(:type)
Method2:
Add a user[]
as a name to the input in the edit form.
Will elaborate the method 1 if you add the edit form.
Method3:
The other solution is to add the user key to the parameters.
def update
if current_admin
params.user = {
"type": params.type,
"id": params.id
}
if @user.update(user_params)
redirect_to users_path
else
render 'edit'
end
end
end
private
def user_params
params.require(:user).permit(:type)
end
reference to api documentaiton
Related Topics
Rails Migration Changing Column to Use Postgres Arrays
How to Switch to an Older Version of Rails
How to Install Ruby-Debug in Ruby 1.9.3/Rails 3.2.1
Logging All Method Calls in a Rails App
Ruby: Extracting Words from String
How to Set an Option as Selected Using Selenium Webdriver (Selenium 2.0) Client in Ruby
Ruby/Sinatra - Serving Up CSS, JavaScript, or Image Files
Ruby - Determining Method Origins
How to Access (Devise) Current_User in a Rspec Feature Test
What Would a Default Getter and Setter Look Like in Rails
Rails: Copying Attributes from an Object to Another Using the "Attributes" Method
Coding Style Checker or Code Formatter for Ruby/Rails
Sprockets::Circulardependencyerror in Store#Index
How to Use Watir::Waiter::Wait_Until to Force Chrome to Wait