Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Rails flash notice won't go away in Safari?

flash sessions safari

  • Please log in to reply
42 replies to this topic

#21 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 12 December 2013 - 12:18 PM

OK I have some follow-up info on this issue. I set up a new topic branch on my local git repo, and then removed every gem not necessary for the app to start. I also removed the calls in application.html.erb which load the css and javascript. Oddly, when testing the app in this state, the same flash issue persisted in Safari, and, as usual, was absent in Chrome.

 

To better illustrate, I made a second screen recording where I go into a bit more detail. View it on YouTube here.

 

It appears to me that this issue is definitely connected to how Rails and Safari interact with sessions.



#22 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 12 December 2013 - 12:36 PM

What version of Ruby are you using?


Programming is just about problem solving!


#23 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 12 December 2013 - 12:37 PM

% ruby -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.5.0]


#24 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 12 December 2013 - 12:48 PM

I am unable to reproduce this issue.

I run a linux box and I have installed the windows version of Safari which is running under wine and created a simple app witrh Rails 4.0.2 and ruby 2.0.0p353 which is basically a security patch so should not be functional differences between this patch and the patch you are running.

 

So maybe this issue doesn't occur in the version of Safari that I am using or maybe this is something else. It could even be one of those "Doh! Forgot about that" moments

 

What is really curious is that the error flash goes away and that this is only an issue with the caution key.

Could you try something really dumb, change the flash key from :caution to :error.

If this solves the issue then search your code for instances of :caution and double check you are not setting it somewhere else.


Programming is just about problem solving!


#25 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 12 December 2013 - 01:09 PM

Yep, it could definitely be a very version-specific issue. As a note of clarification, this is not limited to flash[:caution]. flash[:error] also sticks. As I show in the video, when you enter junk in the search bar, that throws flash[:error]. If a valid (numeric) id is entered and not found, that throws flash[:caution]. I have tried playing around with those names, but it doesn't change things.

 

So in the layout we have the flash code which inserts the key (:error, :caution, :success, etc.) into the div's class...

<% flash.each do |key, value| %>
  <div data-alert class="alert-box cbc-<%= key %>">
    <%= value %>
    <a href="#" class="close">&times;</a>
  </div>
<% end %>

referencing this... (or a slight variation for :caution or :success)

.cbc-error {
  @include alert();
  @include radius($alert-radius);
  color: darken($alert-color, 15%);
  background-color: #f2dede;
  border: 1px solid #ebccd1;
  a.close {
    color: $alert-color;
  }
}

and outputting this.

<div data-alert class="alert-box cbc-error">
  <i class="fa fa-times fa-fw"></i> Please enter a numeric student ID.
  <a href="#" class="close">&times;</a>
</div>

Also of note is that these same flash keys are universal throughout the app. Everywhere else they are called, they behave as expected.



#26 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 12 December 2013 - 01:14 PM

As an addendum, here are the results of an app-wide search for ":caution". As you can see, it is limited to flash calls.

Searching 1185 files for ":caution"

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/application_controller.rb:
   17      def signed_in_coach
   18        unless signed_in?
   19:         flash[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Please sign in first.].html_safe
   20          store_location
   21          redirect_to signin_url

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/query_controller.rb:
   25          @page_header = @active_nav = "Query"
   26          params[:last_name_query] = nil
   27:         flash.now[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Your search did not return any results.].html_safe
   28          render 'query_page'
   29        end
   ..
   47          @page_header = @active_nav = "Query"
   48          params[:first_name_query] = nil
   49:         flash.now[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Your search did not return any results.].html_safe
   50          render 'query_page'
   51        end
   ..
   69          @page_header = @active_nav = "Query"
   70          params[:full_text_search] = nil
   71:         flash.now[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Your search did not return any results.].html_safe
   72          render 'query_page'
   73        end
   ..
   90        else
   91          @page_header = @active_nav = "Query"
   92:         flash.now[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Your search did not return any results.].html_safe
   93          render 'query_page'
   94        end

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/students_controller.rb:
  101          redirect_to @student
  102        else
  103:         flash[:caution] = %Q[<i class="fa fa-warning fa-fw"></i> Sorry, we couldn't find a student with ID #{id}.].html_safe
  104          redirect_to session.delete(:return_to)
  105        end

6 matches across 3 files

And also ":error". Slightly more matches here, but still I don't see anything that could be causing flash messages to stick in only one browser and only in connection with one action.

Searching 1185 files for ":error"

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/coaches_controller.rb:
   34      else
   35        @page_header = "New Coach"
   36:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem. Please correct the highlighted fields below.].html_safe
   37        render 'new'
   38      end
   ..
   51      else
   52        @page_header = full_name(@coach)
   53:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem. Please correct the highlighted fields below.].html_safe
   54        render 'show'
   55      end

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/comments_controller.rb:
   24        @page_header = @student.student_name
   25        @current_lesson = @student.lessons.find_by_number(@student.current_lesson)
   26:       flash[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, you can't post a blank comment.].html_safe
   27        redirect_to @commentable
   28      end
   ..
   45        redirect_to @commentable
   46      else
   47:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem.].html_safe
   48        @page_header = @student.student_name
   49        render 'edit'

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/lessons_controller.rb:
   40        redirect_to student_path(@student)
   41      else
   42:       flash[:error] = "Well, that didn't work."
   43        redirect_to student_path(@student)
   44      end

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/query_controller.rb:
   12      if params[:last_name_query].empty?
   13        @page_header = @active_nav = "Query"
   14:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a valid search term.].html_safe
   15        render 'query_page'
   16      else
   ..
   34      if params[:first_name_query].empty?
   35        @page_header = @active_nav = "Query"
   36:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a valid search term.].html_safe
   37        render 'query_page'
   38      else
   ..
   56      if params[:full_text_search].empty?
   57        @page_header = @active_nav = "Query"
   58:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a valid search term.].html_safe
   59        render 'query_page'
   60      else
   ..
   78      if empty_query?(params)
   79        @page_header = @active_nav = "Query"
   80:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please select at least one query option.].html_safe
   81        render 'query_page'
   82      else

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/sessions_controller.rb:
   11        redirect_back_or root_path
   12      else
   13:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Invalid email/password combination].html_safe
   14        render 'new'
   15      end

/Users/joshukraine/Dev/Projects/cbcadmin/app/controllers/students_controller.rb:
   40      else
   41        @active_nav = @page_header = "New Student"
   42:       flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem. Please correct the highlighted fields below.].html_safe
   43        render 'new'
   44      end
   ..
   65          @coaches = Coach.all
   66          @page_header = @student.student_name
   67:         flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem. Please correct the highlighted fields below.].html_safe
   68          render 'edit'
   69        end
   ..
   77        else
   78          @page_header = @student.student_name
   79:         flash.now[:error] = %Q[<i class="fa fa-times fa-fw"></i> Oops, we've had a problem. Please correct the highlighted fields below.].html_safe
   80          render 'edit'
   81        end
   ..
   93      session[:return_to] ||= request.referer
   94      if params[:search].to_i.zero?
   95:       flash[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a numeric student ID.].html_safe
   96        redirect_to session.delete(:return_to)
   97      else

/Users/joshukraine/Dev/Projects/cbcadmin/config/initializers/simple_form.rb:
    7    # whole input.
    8    config.wrappers :default, :class => :input,
    9:     :hint_class => :field_with_hint, :error_class => :field_with_errors do |b|
   10      ## Extensions enabled by default
   11      # Any of these extensions can be disabled for a
   ..
   43      b.use :input
   44      b.use :hint,  :wrap_with => { :tag => :span, :class => :hint }
   45:     b.use :error, :wrap_with => { :tag => :span, :class => :error }
   46    end
   47  

/Users/joshukraine/Dev/Projects/cbcadmin/config/initializers/simple_form_foundation.rb:
    3    config.wrappers :foundation, :class => :input,
    4                    :hint_class => :field_with_hint,
    5:                   :error_class => :error do |b|
    6      b.use :html5
    7      b.use :placeholder
    .
   11      b.optional :readonly
   12      b.use :input
   13:     b.use :error, :wrap_with => { :tag => :small }
   14  
   15      # Uncomment the following line to enable hints. The line is commented out by default since Foundation
   ..
   20    config.wrappers :found_with_labels, :class => :input,
   21                    :hint_class => :field_with_hint,
   22:                   :error_class => :error do |b|
   23      b.use :html5
   24      b.use :placeholder
   ..
   29      b.use :label
   30      b.use :input
   31:     b.use :error, :wrap_with => { :tag => :small }
   32  
   33      # Uncomment the following line to enable hints. The line is commented out by default since Foundation

/Users/joshukraine/Dev/Projects/cbcadmin/spec/models/comment_spec.rb:
   62        expect do
   63          Comment.new(commentable_id: student.id)
   64:       end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
   65      end
   66  
   ..
   75        expect do
   76          Comment.new(commenter_id: coach.id)
   77:       end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
   78      end
   79  
   ..
   88    #     expect do
   89    #       Comment.new(commentable_id: lesson.id)
   90:   #     end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
   91    #   end
   92  

/Users/joshukraine/Dev/Projects/cbcadmin/spec/models/lesson_spec.rb:
   58        expect do
   59          Lesson.new(student_id: student.id)
   60:       end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
   61      end
   62    end

/Users/joshukraine/Dev/Projects/cbcadmin/spec/models/reminder_spec.rb:
   49        expect do
   50          Reminder.new(student_id: student.id)
   51:       end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
   52      end
   53    end

/Users/joshukraine/Dev/Projects/cbcadmin/spec/models/student_spec.rb:
  219        expect do
  220          Student.new(coach_id: coach.id)
  221:       end.to raise_error(ActiveModel::MassAssignmentSecurity::Error)
  222      end
  223  

29 matches across 12 files



#27 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 12 December 2013 - 03:21 PM

So what is the difference between flash messages that stick and flash messages that don't stick? Are there any that don't stick ever under any circumstances?

Redirects? Probably nothing to do with it.

 

How could this be related, if at all, to assets not getting reloaded on a full page refresh? I think there may be a relation. Something is causing cached pages to show maybe? Instead of a full refresh. What caching have you implemented if any?

 

Just thinking out loud but it HAS to be related to caching or cookies in some way.


Programming is just about problem solving!


#28 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 12 December 2013 - 06:24 PM

Good thoughts. Here's a few observations/answers to some of your questions.

  1. There is nothing whatsoever different about the flash messages that are sticking as compared with those that don't. The odd-ball feature here is the session[:return_to] redirect. In every other case in the app, flash notices occur after a render or redirect to a pre-defined page. So there aren't any other flash messages that stick - even in Safari. It's only the ones that occur after the session[:return_to] redirect.
  2. As for assets not loading, if by assets we mean css and js files, it seems unlikely that those are at all involved. We've already demonstrated that the problem can be reproduced in an HTML-only environment. What seems to be happening here is not that assets aren't loading, but that the HTML is  not being rendered, though I realize the log seems to contradict that.
  3. As for caching, there could be something there, though I have not setup anything to manage caching, either in the app or the browser.

So to sum up, my money is on the sessions/cookies at this point. That's the only factor which separates the search bar functionality from every other flash-related action in the app. In particular, it would be interesting to find out why clicking the Safari bookmark (a hard-coded call to the full root url) clears the flash while clicking a link in the app with a relative path does not.



#29 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 December 2013 - 06:26 AM

it would be interesting to find out why clicking the Safari bookmark (a hard-coded call to the full root url) clears the flash while clicking a link in the app with a relative path does not.

 

 

Because those links behave differently.

 

Could be using javascript? Are you using turbo links? You commented out javascript in your last test so it can;t be that.

 

All that is left is some form of caching.

 

I still think that the assets failing to load on full page refreshes could be a symptom of the same problem. Did this go away when you commented everything out?

 

If I were in your shoes right now, I would start a new app from scratch that has the basic bare minimum code to reproduce the problem and then try it with different Rails versions. Specifically Rails 4. This will eliminate this being a Rails version specific issue. Although I am sure if it was a Rails related bug it would have been picked up on by now.


Programming is just about problem solving!


#30 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 December 2013 - 06:46 AM

Picking up on Point 1 that you made

 

There is nothing whatsoever different about the flash messages that are sticking as compared with those that don't. The odd-ball feature here is the session[:return_to] redirect. In every other case in the app, flash notices occur after a render or redirect to a pre-defined page. So there aren't any other flash messages that stick - even in Safari. It's only the ones that occur after the session[:return_to] redirect.

 

 

What is the value of session[:return_to]?

 

What happens if you change it to

path = session[:return_to]
session[:return_to].delete
redirect_to path

Does this have any effect? It shouldn't but it may. My experience tells me that something weird could just be happening when doing stuff like this that is out of the ordinary and as this is the only difference that you are able to tell then it has to be worth a try.


Programming is just about problem solving!


#31 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 13 December 2013 - 01:32 PM

No I am not using turbo links. Also, the page blank-out phenomenon occurred even when all gems, css, and js were commented out. (I show this in the second video.)

 

As to your question about the value of session[:return_to], I don't know how to check this, though I assume it must be in some way equivalent to the referring path. I tried the code block you suggested:

path = session[:return_to]
session[:return_to].delete
redirect_to path

but that threw a wrong number of args error. So I adjusted it to this:

session[:return_to] ||= request.referer
    if params[:search].to_i.zero?
      path = session[:return_to]
      session.delete(:return_to)
      flash[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a numeric student ID.].html_safe
      redirect_to path
    else
.
.
.

As you suspected, that didn't make any difference.

 

I think your idea about testing this in a fresh app - possibly Rails 4 - sounds like a good one. I'm in the middle of some more pressing tasks right now, so that may have to wait a few days. But I'll be sure to let you know how it goes. Thanks as always!



#32 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 December 2013 - 03:56 PM

logger is your friend :)

logger.debug("@@@@ Return path: #{session[:return_to]}")

This will output strings to the log file and hence also to the console that is running the server along with the normal output that get's logged but the debug will not output in a production environment. There are various log levels you can use (warn, info).

the @@@@ symbols make your output stand out from the rest of the messages that get output so you can quickly identify the info you are looking for. You can of course output any string you want.

 

It is a great way of tracing your code to check that what you think is happening is actually what is happening. Beats having to run traces in debug mode.


Programming is just about problem solving!


#33 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 December 2013 - 04:00 PM

Because I am unable to re-produce the problem I'm not sure how much more help I can be with this but feel free to ask away if you have questions. I have just about exhausted all my thoughts. I am left with the thought that you need to concentrate on the differences between the way;s that work and the ways that don't and not to get clouded with side issues.


Programming is just about problem solving!


#34 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 13 December 2013 - 04:09 PM

Thanks, James. I'll try the logger and see what I come up with. At this point, I'm considering the possibility of just making a separate landing page for unsuccessful searches. This seems to be a fairly common practice on sites that use this type of "search-from-anywhere" feature, plus it would give me a concrete place to aim my redirect.

 

Thanks again for all your help. It's been fun! :)



#35 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 13 December 2013 - 05:08 PM

Sure, but that doesn't fix the issue. It may come back to bite if you don;t get to the bottom of it. It could well be a Rails bug, in which case it needs reporting to https://github.com/rails/rails/issues

 

Might even be worth reporting anyway and pointing to this thread. You may get someone better able to help resolve the issue.


Programming is just about problem solving!


#36 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 15 December 2013 - 04:39 PM

Hey James,

 

Just a couple of updates on this. First, I took your suggestion and posted a new issue to the Rails repo on GitHub: https://github.com/r...ls/issues/13331

 

Also, as I was searching the web again today for new clues, I came across an older RailsCast where RyanBates does essentially the same thing I'm trying to do: send a user back to the page he came from and display a flash notice. Of note is the fact that he is using Safari. Here's the link to the RailsCast: http://railscasts.co.../131-going-back His code is very similar to mine and also relies on the request referrer.

 

Lastly, I've been playing around with the logger as you suggested, and below is some output from Chrome vs. Safari. Oh, and before I forget, I wanted to mention that I've tried this now on Safari in iOS 7, and the same problem occurs there too. As expected, Chrome for iOS clears the flash just fine.

 

So now the code. First, I've inserted three logger lines into my search action like so:

def search
  session[:return_to] ||= request.referer
  if !params[:search].numeric?
    flash[:error] = %Q[<i class="fa fa-times fa-fw"></i> Please enter a numeric student ID.].html_safe

    logger.debug("@@@@ flash: #{flash}")
    logger.debug("@@@@ session: #{session}")
    logger.debug("@@@@ request.referer: #{request.referer}")

    redirect_to session.delete(:return_to)
  else
.
.
.

I've added the same lines to PagesController#home:

def home
  redirect_to signin_url unless signed_in?
  @active_nav = "Dashboard"

  logger.debug("@@@@ flash: #{flash}")
  logger.debug("@@@@ session: #{session}")
  logger.debug("@@@@ request.referer: #{request.referer}")
end

In all cases, I'm entering non-numeric strings into the search field. And now the results, Chrome first, then Safari. (comments mine)

# In Chrome, start on home page, enter invalid input. Flash is displayed

Started GET "/students/search?utf8=%E2%9C%93&search=asdf&submit=%EF%80%82" for 127.0.0.1 at 2013-12-15 18:31:12 +0200
Processing by StudentsController#search as HTML
  Parameters: {"utf8"=>"✓", "search"=>"asdf", "submit"=>"?"}
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2cda87290>
@@@@ session: {"session_id"=>"0d3e2d6679ba059a32fda992098d76bb", "_csrf_token"=>"FCi64KNpqW1ty7YTNibievP8VlmVm/PnGxWtNp0ylBM=", "return_to"=>"http://localhost:3000/"}
@@@@ request.referer: http://localhost:3000/
Redirected to http://localhost:3000/
Completed 302 Found in 4.1ms (ActiveRecord: 0.4ms)


Started GET "/" for 127.0.0.1 at 2013-12-15 18:31:12 +0200
Processing by PagesController#home as HTML
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d032cd08>
@@@@ session: {"session_id"=>"0d3e2d6679ba059a32fda992098d76bb", "_csrf_token"=>"FCi64KNpqW1ty7YTNibievP8VlmVm/PnGxWtNp0ylBM=", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007fa2d032cd08 @used=#<Set: {:error}>, @closed=false, @flashes={:error=>"<i class=\"fa fa-times fa-fw\"></i> Please enter a numeric student ID."}, @now=nil>}
@@@@ request.referer: http://localhost:3000/
  Rendered pages/home.html.erb within layouts/application (0.0ms)
  Rendered layouts/_top-nav.html.erb (2.0ms)
  Rendered layouts/_sidenav.html.erb (1.2ms)
Completed 200 OK in 19.4ms (Views: 16.2ms | ActiveRecord: 0.4ms)



# Click link to go back to home page, flash clears.

Started GET "/" for 127.0.0.1 at 2013-12-15 18:32:17 +0200
Processing by PagesController#home as HTML
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d03d7ac8>
@@@@ session: {"session_id"=>"0d3e2d6679ba059a32fda992098d76bb", "_csrf_token"=>"FCi64KNpqW1ty7YTNibievP8VlmVm/PnGxWtNp0ylBM=", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007fa2d03d7ac8 @used=#<Set: {}>, @closed=false, @flashes={}, @now=nil>}
@@@@ request.referer: http://localhost:3000/
  Rendered pages/home.html.erb within layouts/application (0.1ms)
  Rendered layouts/_top-nav.html.erb (1.9ms)
  Rendered layouts/_sidenav.html.erb (1.0ms)
Completed 200 OK in 66.8ms (Views: 16.6ms | ActiveRecord: 0.4ms)

And now Safari....

# Now in Safari. Start on homepage, enter invalid input. Flash is displayed

Started GET "/students/search?utf8=%E2%9C%93&search=asfsdf&submit=%EF%80%82" for 127.0.0.1 at 2013-12-15 18:33:01 +0200
Processing by StudentsController#search as HTML
  Parameters: {"utf8"=>"✓", "search"=>"asfsdf", "submit"=>"?"}
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d053d5e8>
@@@@ session: {"session_id"=>"996952e20fbf975af7a4396f8a3aa7da", "_csrf_token"=>"EwfOi3Ny0GDZXOIeHwG7NHcwbwr3WR2c6qPk6zSHRNU=", "return_to"=>"http://localhost:3000/"}
@@@@ request.referer: http://localhost:3000/
Redirected to http://localhost:3000/
Completed 302 Found in 3.9ms (ActiveRecord: 0.4ms)


Started GET "/" for 127.0.0.1 at 2013-12-15 18:33:01 +0200
Processing by PagesController#home as HTML
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d05d6900>
@@@@ session: {"session_id"=>"996952e20fbf975af7a4396f8a3aa7da", "_csrf_token"=>"EwfOi3Ny0GDZXOIeHwG7NHcwbwr3WR2c6qPk6zSHRNU=", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007fa2d05d6900 @used=#<Set: {:error}>, @closed=false, @flashes={:error=>"<i class=\"fa fa-times fa-fw\"></i> Please enter a numeric student ID."}, @now=nil>}
@@@@ request.referer: http://localhost:3000/
  Rendered pages/home.html.erb within layouts/application (0.0ms)
  Rendered layouts/_top-nav.html.erb (1.9ms)
  Rendered layouts/_sidenav.html.erb (0.9ms)
Completed 200 OK in 18.7ms (Views: 15.7ms | ActiveRecord: 0.4ms)



# Click link to go back to home page, flash sticks.

Started GET "/" for 127.0.0.1 at 2013-12-15 18:34:20 +0200
Processing by PagesController#home as HTML
  Coach Load (0.4ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d048f240>
@@@@ session: {"session_id"=>"996952e20fbf975af7a4396f8a3aa7da", "_csrf_token"=>"EwfOi3Ny0GDZXOIeHwG7NHcwbwr3WR2c6qPk6zSHRNU=", "flash"=>#<ActionDispatch::Flash::FlashHash:0x007fa2d048f240 @used=#<Set: {}>, @closed=false, @flashes={}, @now=nil>}
@@@@ request.referer:
  Rendered pages/home.html.erb within layouts/application (0.0ms)
  Rendered layouts/_top-nav.html.erb (1.8ms)
  Rendered layouts/_sidenav.html.erb (0.9ms)
Completed 200 OK in 16.6ms (Views: 13.7ms | ActiveRecord: 0.4ms)



# Click browser bookmark which points to http://localhost:3000/ Flash clears.

Started GET "/" for 127.0.0.1 at 2013-12-15 18:35:07 +0200
Processing by PagesController#home as HTML
  Coach Load (0.3ms)  SELECT "coaches".* FROM "coaches" WHERE "coaches"."remember_token" = 'qnT_bGpti6JLWWLtFaM7DA' ORDER BY coaches.created_at ASC LIMIT 1
@@@@ flash: #<ActionDispatch::Flash::FlashHash:0x007fa2d07a4a98>
@@@@ session: {"session_id"=>"996952e20fbf975af7a4396f8a3aa7da", "_csrf_token"=>"EwfOi3Ny0GDZXOIeHwG7NHcwbwr3WR2c6qPk6zSHRNU="}
@@@@ request.referer:
  Rendered pages/home.html.erb within layouts/application (0.0ms)
  Rendered layouts/_top-nav.html.erb (1.9ms)
  Rendered layouts/_sidenav.html.erb (0.9ms)
Completed 200 OK in 62.9ms (Views: 14.4ms | ActiveRecord: 0.3ms)

Not sure if this changes anything, but thought I would at least post it for documentation purposes. Cheers!



#37 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 15 December 2013 - 09:26 PM

I've created a test app that contains the search functionality and pushed it to GitHub. I have successfully reproduced this bug with the test app. Steps to reproduce are in README.md in the repo.
 
 


#38 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 16 December 2013 - 09:23 AM

Hhhmm! It will be interesting to see what the Rails team come back with. Nice job on the testing.


Programming is just about problem solving!


#39 joshukraine

joshukraine

    Signalman

  • Members
  • 20 posts

Posted 16 December 2013 - 09:28 AM

Well, over the last few hours, the issue has been reproduced by at least one other person besides myself using Safari 7. I also tried it with an older version of Safari this morning (Safari 5, Snow Leopard) and could not reproduce the issue there. All this points to it being a Safari 7 bug. Apparently the Rails people agree because they commented as much and closed the issue.

 

https://github.com/r...ls/issues/13331

 

Thanks again for all your input here. It's been interesting working on it. Hopefully Apple will sort this out in a future version of Safari. Cheers!



#40 james

james

    Guard

  • Moderators
  • 221 posts
  • LocationLeeds, U.K.

Posted 16 December 2013 - 09:50 AM

Well, at least the culprit has been identified and the community now has a "known issue" which is great news, there is nothing worse than an unknown bug, but you are left with no solution, so I guess you need to work out a way of redirecting without using request.referrer.

 

One option might be to set the session[:return_to] value using filters in the application controller. I think the after_action, or after_filter in your version of rails will do the job for you. So set the return_to in an after_filter in the application controller and comment_out any other code you have that currently sets the :return_to value. It should should solve the issue for you.

 

This may throw up occasional anomolies that I can't quite think of at this time in the morning, sop make the method called by the after_filter in a protected section of the application controller that way it can be overidden by any other controller/action if you find a case where it may not be desirable to redirect back to a particular action. Like I say, I can;t think of any reason why this might be the case exccept a delete, or create action but you can add an exception to those as part of the filter

after_filter :set_redirect_to, except: [create, delete]

Should do the trick


Programming is just about problem solving!






Also tagged with one or more of these keywords: flash, sessions, safari

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users