0

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

Community
  • 1
  • 1
user1455116
  • 2,034
  • 4
  • 24
  • 48
  • Are you sure you're hitting the right controller action? – nicholaides Jul 06 '12 at 17:32
  • @nicholaides i found that i should not be using redirect, the controller has 'check_validity' action with method 'post' and added the route post "controller/check_validity' in my routes. – user1455116 Jul 06 '12 at 17:35

1 Answers1

0

i think i solved the problem.

In the login method i used the following code

  def login

  respond_to  do |format|   
  format.html
  end

  end

When i removed the respond_to block, i was able to execute the code. But i still do not know why this is happening. Is the respond to tag looking for check_validity.html.erb instead of login.html.erb?

user1455116
  • 2,034
  • 4
  • 24
  • 48