mrg mrg - 1 year ago 132
Ruby Question

Handling Parameters in Rails

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


<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">

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,


ass LoginController < ApplicationController
def auth


Answer Source

something like this:

if params[:username].present? && params[:password].present? 
  #do something
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download