On Jul 10, 10:13 pm, Julia Lovel <[email protected]>
wrote:
> <td>User name:
> <%= text_field("userform", "user_name",:size=>"20" ) %></td><br>
> <td>Password:
> <%= password_field("userform", "password",:size=>"20" )
> %></td><br>
> <td> <%= javascript_include_tag :defaults %>
> <%= submit_tag 'LOG IN', :onclick =>remote_function(:url =>
> {:action => :authenticate, } ) %></td><br>
> <td><input type='submit' value=' Close me! '
> onClick='document.getElementById("loginpopup").style.display = "none"'>
> </td>
> </tr>
>
Because you're just using an onclick on the submit tag this isn't
going to know that you want it to submit these form parameters. Why
not use remote_form_for ?
It's also pretty weird to have the tags to load javascript where you
have put them.
> And here is the code from my controller for the authentication action I
> am calling on:
>
> class UserController < ApplicationController
> def authenticate
> @user = User.new(params[:userform])
> valid_user = User.find(:first,:conditions => ["user_name = ? and
> password = ? ",@user.user_name, @user.password])
> if valid_user
> session[:user_id]=valid_user.user_name
> redirect_to :action => 'private'
> else
> flash[:notice] = "Invalid User/Password"
> redirect_to :action=> 'login'
> end
You've not told remote_function that you want to update a page element
so unless you send back some javascript. You're just doing a redirect
in your authenticate action, however that redirect just redirects the
ajax request you made - it won't affect the page the user is on at
all. if you actually wanted to redirect them to the private page you
would need to use rjs (or generate the appropriate javascript by
hand). If what you wanted was to redirect them to the private action
then why use ajax at all ?
> When I tried typing the code
> submit_tag 'LOG IN', :onclick =>remote_function(:url =>
> {:action => :authenticate, } )
> into irb, I got this error message:
> NoMethodError: undefined method `remote_function' for main:Object
>
That's because functions like remote_function are only included in
your views. If you use rails' script/console there is an object called
something like helpers which has the various view helper methods
included.
Fred
> There may be a simple error that I am making, as I am pretty new to the
> ruby language. Also, if anyone knows another way to do this that will
> work with the partial rendering I use to display the login box, that
> would be fine, too.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---