mrg mrg - 2 months ago 19
Ruby Question

Handling Parameters in Rails

How to validate parameter passed to the controller from view. The following is my view file.

index.html.erb:

<html>
<body>
<center> <h1> Login form </h1> </center>
<form action='/login/auth' method='GET'>
Name: <input type="text" name="username" width=20>
Password: <input type="password" name="password" width=20>
<input type="submit" value="login">
</form>
</body>
</html>


The above is the view file rendered in client side when the client calls '/login' controller. So, once the value is filled and
press the submit button, the datas are passed to '/login/auth' action. With in auth method how to handle the data which is passed from
client side. My controller file is,

login_controller.rb:

ass LoginController < ApplicationController
def auth

end
end

Answer

something like this:

if params[:username].present? && params[:password].present? 
  #do something
end
Comments