ramya
ramya

Reputation: 928

Getting signed out of the ruby application

I am having a ruby on rails application.I added a new section called reports to the application. It has no model but a controller and many forms in the views folder. The functionality is working as desired. The problem I am facing facing is on clicking the submit button, the user who is signed in is signed out automatically.

My code is :

Reports Controller:

    class ReportsController < ApplicationController
    def index
    @projects=Project.find(:all)
    @releases=Release.find(:all)
    @cycles=Cycle.find(:all)   
    report_type=params[:report_type]
    if report_type=="1" && params[:cycles]     
    @cycle=Cycle.find(params[:cycles])
    @[email protected]     
    puts " report_type===#{report_type}"
    end
    end


    def  update_releases 
     puts "inside releases"
     project = Project.find(params[:project_id]) 
@releases = project.releases
respond_to do |format| 
format.js 
end
end


def update_cycles 
puts "inside update_cycles"
release = Release.find(params[:release_id]) 
@cycles =release.cycles
respond_to do |format| 
format.js    
end 
end 
end

In index.html.haml :

-set_title "Reports"
-content_for :content_title do
  = link_to "Test Case Manager", "/"
  &raquo;
  = "Reports"
%table.grid.full
%tr
    %td.grid.full_panels{:style => "width: 30%"}
      -panel "Reports" do
        = render "reports",:report_type=>params[:report_type]
    %td.grid.full_panels{:style => "width: 70%"}
      -table_panel "Report details" do
        = render "report_details",:report_type=>params[:report_type]
= javascript_include_tag "pages/ic"

_reports.html.haml:

%table.grid.full
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      =link_to 'Test Not Run Per Cycle',reports_path(:report_type=>1)
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Result Comparison',reports_path(:report_type=>2)
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Summary'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Tester summary per cycle'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Test Cycle Failure Report'
  %tr
    %td.grid.full_panels{:style => "width: 10%"}
      = link_to 'Release Test Results Summary'
= javascript_include_tag "pages/ic"

_report_details.html.haml:

-if report_type == "1" 
   = render "tests_not_run_per_cycle",:report_type=>report_type  
   = render "tests_not_run_per_cycle_reports",:report_type=>params[:report_type]

_tests_not_run_per_cycle.html.haml:

-projects=Project.all
-releases = Release.all
-cycles=Release.all
-form_tag reports_path(),:method => :get, :multipart => true  do  
  %table.grid.full_panels
  %tr      
  %td.grid.full_panels{:style => "width: 20%"}
    Project:
  %td.grid.full_panels{:style => "width: 20%"}
    //= select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]),{:onchange => "#{remote_function(:url  => {:action => "update_releases"},:with => "'project_id='+value")}"} 
    = select_tag "projects",options_from_collection_for_select(projects,"id","name",params[:projects]), :class => "update_releases",:include_blank=>true
    //= select_tag 'projects',options_from_collection_for_select(projects, "id", "name"),:'data-remote' => 'true', :'data-url' => 'reports/update_releases', :'data-type' => 'json'  
    =hidden_field_tag "report_type","1"
  %td.grid.full_panels{:style => "width: 20%"}
    Releases:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="releases">
    = render :partial => 'releases', :object => @releases
  %td.grid.full_panels{:style => "width: 20%"}
    Cycles:
  %td.grid.full_panels{:style => "width: 20%"}
    <div id="cycles">
    = render :partial => 'cycles', :object => @cycles

%tr      
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
    =submit_tag "Submit"
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}
  %td.grid.full_panels{:style => "width: 20%"}      
= javascript_include_tag "pages/ic"

_tests_not_run_per_cycle_reports:

-if report_type=="1" && params[:cycles]
   -ic_to_platform_config = @cycle.ic_platform_configs
   %table
    %th Root
    %th Suite
    %th Case
    %th IC
    %th Executor
    %th Platform
    [email protected] do |ic|
      %tr
    -ic_model=Ic.find(ic.id)
    - [email protected]_ic_rev_assign(ic_model)
    - populate_table ic_rev, ic_to_platform_config[ic_model]
 = javascript_include_tag "pages/ic"

On clicking the submit button the user signed in gets signed out automatically.Please help me out here.

Thanks, Ramya.

Upvotes: 0

Views: 95

Answers (1)

Graham Savage
Graham Savage

Reputation: 1164

I had a similar problem a while back - the underlying problem is that if you do a POST request to a Rails application, and your post request does not have an authenticity token as one of the parameters, Rails deletes its session, which usually causes the user to be logged out.

Take a look at the HTML source of your generated form -- does it contain a hidden input field called authenticity token?

There are a couple of solutions, one would be to skip that check on the server, but the better solution would be to add the authenticity token to the form. Try adding this to the head section of your layout HAML file:

= csrf_meta_tag

I think that is enough to fix your problem

Upvotes: 2

Related Questions