Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple require & permit strong parameters rails 4

In the below case, i am trying to use strong parameters. I want to require email_address, password and permit remember_me fields.

But using like below it only allows the LAST line in the method Ex:- In below case it only take params.permit(:remember_me)

  private

  def registration_params
    params.require(:email_address)
    params.require(:password)
    params.permit(:remember_me)
  end

Another Ex:- In this below case, if i rearrange it like below it will take only params.require(:email_address) where am i going wrong ?

  def registration_params
    params.require(:password)
    params.permit(:remember_me)
    params.require(:email_address)
  end

UPDATE Params hash be like

{
              "utf8" => "✓",
     "email_address" => "[email protected]",
          "password" => "password123",
       "remember_me" => "true",
            "commit" => "Log in",
        "controller" => "registration",
            "action" => "sign_in"
}
like image 359
Rahul Dess Avatar asked Sep 16 '15 15:09

Rahul Dess


People also ask

Where do we use require?

require() is used to consume modules. It allows you to include modules in your app. You can add built-in core Node. js modules, community-based modules (node_modules), and local modules too.

Why do we use require?

require is typically used with NodeJS to read and execute CommonJS modules. These modules can be either built-in modules like http or custom-written modules. With require , you can include them in your JavaScript files and use their functions and variables.

What is the require stack?

Require Stack is a wrapper around require method, which makes it easier to get syntax error with proper error stack when wrapping require call under try/catch block.

What is require method?

require() statement basically reads a JavaScript file, executes it, and then proceeds to return the export object. require() statement not only allows to add built-in core NodeJS modules but also community-based and local modules.


1 Answers

Ok found the answer through a friend ...one way to do this is

params.require(:email_address)
params.require(:password)
params.permit(
:email_address,
:password,
:remember_me
)

Works good.

like image 147
Rahul Dess Avatar answered Oct 06 '22 00:10

Rahul Dess