Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value of a specific param - Rails

In a specific controller I have the below list of params:

Parameters: {"user"=>"{\"id\":32,\"email\":\"[email protected]\",\"created_at\":\"2014-04-10T13:13:40.000Z\",\"updated_at\":\"2014-04-11T18:10:15.000Z\"}"}

How I can get the value of email for example?

like image 959
darkcode Avatar asked Dec 08 '22 08:12

darkcode


2 Answers

You can do

params[:user][:email] #=> "[email protected]"

Which gives you the params of email attribute of user.

like image 72
Pavan Avatar answered Dec 23 '22 20:12

Pavan


You value looks like json.

So try this

user_params = ActiveSupport::JSON.decode(params[:user])
user_params[:email]

or

require 'json'
user_params = JSON.parse(params[:user])
user_params[:email]
like image 23
usha Avatar answered Dec 23 '22 18:12

usha