0

My session controller

class SessionsController < ApplicationController
skip_before_filter :is_loggedin?, :only => [:new, :create]

def new
render :action => "new", :layout => false
end

def create
render :update do |page|
  if !params[:email].blank? && !params[:password].blank?
    if user = User.authenticate(params[:email], params[:password])
      if user == "unuser"
        page.alert("Your username and/or password was incorrect.")
      elsif !user.account_id.blank?
        if params[:remember_me]
          cookies.permanent[:user_id] = user.id
        else
          cookies[:user_id]=user.id
        end
        user.update_attributes(:last_login => Time.now, :is_online => true)

        if user.user_type=="mentor"
          page.redirect_to home_mentors_path(:account_id =>user.account_id)
        else
          page.redirect_to home_students_path(:account_id =>user.account_id)
        end
      else
        page.alert("You have not confirmed the activation link yet. Please check your registered email ")
      end
    else
      page << "jQuery('#login_error').html('Invalid user/password');"
    end
  else
    page.alert("You can't leave this empty.")
  end
end

My sessions/_form.htm is like this:
<%= form_tag sessions_path, :remote => true, :method =>"post" do  %>
<div id="login-modal" class="shadow" style="display: block; z-index: 4000;">
<div class="login_bar_top">
  <div class="login_bar_left"></div>
  <div class="login_bar_mid">User Login</div>
  <div class="login_bar_right"></div>
</div>

I have lot of controllers with code render :update do, now it will take lot of time to review all, with respond_to do. I tried by installing prototype-rails gem also. Not solved. Error I am facing is:

Started POST "/sessions" for 127.0.0.1 at 2013-12-10 13:59:50 +0530
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"42cE1Mx5gXzmZAbSwgSnxbbygYLH4x81lbPjkCDKAOs=", "email"=>"mentor@gmail.com", "password"=>"[FILTERED]"}
Completed 500 Internal Server Error in 2ms

ActionView::MissingTemplate (Missing template sessions/update, application/update with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee, :rjs]}. Searched in:
* "/home/prz/project/techzoorails/techzoo3/app/views"
):
app/controllers/sessions_controller.rb:9:in `create'

Previous it was working fine. Is there any solution by keeping render :update code. I am using rails 3.0.9 with ruby 1.9.3p392.

siv rj
  • 1,451
  • 1
  • 14
  • 31
  • 1
    Is a page load happening when you submit the form? or is it an AJAX form submit? – Santhosh Dec 10 '13 at 09:17
  • When did it stop working? Did you upgrade `Rails` ? – Santhosh Dec 10 '13 at 09:46
  • No I didnot upgrade, rails 3.0.9 was the original version when project started. When i had added lot of js files and suddenly stop working where there is render :update do |page| syntax. – siv rj Dec 10 '13 at 09:52
  • Are you sure the same Rails version was used from the beginning and this line was executing `page.alert`? Rails 3 no longer support Prototype and it's replaced by jQuery. http://stackoverflow.com/questions/4016285/rails-3-simple-ajaxy-page-updates – mohamagdy Dec 10 '13 at 09:58
  • From the log -`Processing by SessionsController#create as HTML`. This means the form submission is not happening in `AJAX` – Santhosh Dec 10 '13 at 10:02
  • @mohamagdy: yes it was started with rails 3.0.9. I know rails 3 no longer support Prototype. But this was working fine. Now i need solution if any? – siv rj Dec 10 '13 at 10:03
  • @Santosh: what is best solution – siv rj Dec 10 '13 at 10:09
  • Firs you have to see if there are any js errors on the page, you can do this using firebug(on firefox) or chrome dev tools. Rails uses `'data-remote'` attribute to make ajax requests. If there are any js errors, this will fail, and the form submission will happen normally. – Santhosh Dec 10 '13 at 10:27
  • @Santosh: this is not problem of ajax and js errors. I checked with firebug too. Please mind render :update is not working. – siv rj Dec 10 '13 at 10:34
  • For now issue is solved by removing gem 'remotipart', '~> 1.0' and adding gem 'prototype-rails' – siv rj Dec 10 '13 at 14:23

0 Answers0