Forum: Ruby on Rails respond_to issue

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Raja Bhatia (Guest)
on 2006-04-15 09:43
(Received via mailing list)
I'm having some trouble with respond_to to handle multiple request
types from a single action.

The action:

  def login
    return if request.get? #just show the login.rhtml page on HTTP GET

    self.current_user = User.authenticate(params[:login],
params[:password])

    respond_to do |type|
      type.js   { render }  # renders login.rjs
      type.html do #fallback for standard requests
        if self.current_user
          redirect_back_or_default(:controller => '/account', :action
=> 'index')
          flash[:notice] = "Logged in successfully"
        else
          flash.now[:notice] = "Login or password incorrect. Try again."
        end
      end
    end
  end

I have two views.. the rjs template (login.rjs) and login.rhtml

It seem's as if login.rhtml is rendering on all requests:
Rendering  within layouts/application
Rendering account/login
Rendered account/_login (0.00124)
Rendered account/_login (0.00089)
Rendered shared/_header (0.00070)
Rendered shared/_footer (0.00070)
Completed in 0.01152 (86 reqs/sec)

Any ideas?

Thanks,

Raja
This topic is locked and can not be replied to.