Reputation: 11094
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
Upvotes: 1
Views: 53
Reputation: 1296
You can get the "username" and "password" parameters from params[:username] and params[:password].
For easy and secure authentication process you can use "devise" gem which is widely used for authentication. It's easy to configure and provides the login and signup view pages by default.
URL to follow https://github.com/plataformatec/devise
Upvotes: 1
Reputation: 4615
something like this:
if params[:username].present? && params[:password].present?
#do something
end
Upvotes: 0