as one of you said in my previous question, i attempted to make a post request.
Here is my login view
<%= form_for :check_validity, :method => "post", :url => {:action => "check_validity"} do |f| %>
<%= f.label :username %>
<%= f.text_field :username %><br />
<%= f.label :password %>
<%= f.password_field (:password)%><br />
<%= f.submit "Submit"%>
<% end%>
Since the check_validity
is a post
method, i wrote the below code in my post method
def check_validity
@USER = params[:display_command_list][:username]
@PASS = params[:display_command_list][:password]
@HOST = 'hostname'
Net::SSH.start( @HOST, @USER, :password => @PASS ) do|ssh|
@result = ssh.exec!("command")
end
if(@result =~ /somestring/)
redirect_to display_command_list_path({:username => @USER, :password => @PASS})
else
redirect_to denied_access_path
end
end
But when i enter username and password in login page and click on submit button, it goes to this post method and gives me "Missing template authorization/check_validity"
error. I included post "authorization/check_validity"
in my routes.rb
. It seems that i'm missing something very basic here :(. Please let me know why is it not able to redirect to the paths i mentioned instead of looking for check_validity.html.erb
I remember when we scaffold, and click on new post and submit it, it redirects to create method which is a post request and then automatically redirects to show method which is 'get'.
How is it able to understand that it should go to 'show' after create? I tried to replicate that here but failed. Please help.
Update: I have seen here and understood that we should not use redirect in a POST method. But how would i use this information and go to denied_acess_path
or display_command_list_path
from this check_validity
method