0

As in java, if we use request.GetParameterById, we can get the ID from the html page and we use the ID to the required query and we use prepare statement to form the full query..

In rails I found we have to use find_by_id.. By i havent get the full details how to use of it. Any one please explain me clearly how to use of it.

Thanks in advance

Pavan Kumar
  • 1,735
  • 2
  • 28
  • 47

2 Answers2

4

if you have a form like this

<form action="/users/create" class="new_user" id="new_user" method="post">
  <label for="user_email">Email<br />
  <input id="user_email" name="user[email]" size="30" type="email" value="" /></div>
  <input name="commit" type="submit" value="Sign in" />
</form>

In your controller 'create' action

def create
   email = params[:user][:email]
   #your code
end

a more simple example would be

<input id="search" name="search" size="30" value="" />

you could get this from the corresponding controller action as

search = params[:search]

If you see the log, you could see how these parameters are passing (Ex: log/development.log)

here is a sample

Processing by Devise::SessionsController#new as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"SOTgZaxt3oGsn0UQrK8Bz9dQgDjACGOIoJoxGsfCM7Q=", "user"=>{"email"=>"", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign in"}

HTH

sameera207
  • 16,547
  • 19
  • 87
  • 152
2

Use the Hash params to get your request params. It contains all post and get parameters.

You should read the doc before asking something that simply to find.

Thomas Ruiz
  • 3,611
  • 2
  • 20
  • 33
  • Thank u for suggesting me to read docs. i havetried to find out the equal for getparameterbyid.. But havent get result. Thank u for guiding me.. i have started learning about hash params – Pavan Kumar Dec 14 '12 at 10:28