Implementing SitePoint's Infinite Scolling in rails by Ilya Bodrov-Krukowski - ruby-on-rails

I am implementing, http://www.sitepoint.com/infinite-scrolling-rails-basics/, into my own project.
It works when I type URL directly to browser after I have implemented it in my own project. However, it does not work if I link_to from a different page. It goes back to regular will_paginate, then I hit "reload" button on browser, it starts tp work again.
However, I don't want my users to hit "reload" button every time for making infinite scrolling to work. What might cause this and how can I fix it? Thanks a lot!

It is caused by turbolinks
However, it is not a fix by installing jquery-turbolinks.
After reading turbolinks documents, temporarily disable turbolink for that particular link with
Home (via Turbolinks)
<div id="some-div" data-no-turbolink>
Home (without Turbolinks)
</div>

Related

Turbolinks 5 not changing url in browser for already visited pages

Using turbolinks in my application with rails 4. Basically facing an issue due to turbolinks that when I click on any link_to which already visited , the request goes to server and content of whole page changes but url in browser remains same.
After this on any link I click content changes but browser url remains same. I check by removing turbolinks and then this issue not appears. How can I fix it?
Try with this solution it might help you
<%= link_to "Policy", policy_path, :"data-no-turbolink" => true %>

Why is my RSpec + Capybara test failing to render view?

I use wicked (1.3.1) (not sure if relevant) for an onboarding flow on my rails 5 app. On the last step of my onboarding process, there is an <a> link that navigates to a user#dashboard page.
This works totally fine in all browsers. For some reason that transition does not work in Capybara (rspec 3.7, rspec-rails 3.7.2, Capybara 2.14). The url changes in the automated browser to the desired route, but the page does not render any content, it retains the old view. Visually its as if someone typed in a url but did not press return, however, the controller method and view are getting touched when i debug them. They appear to return a rendering, but the value is not rendered in the browser
If i throw a sleep in my test after the <a> click, I can manually click on the url bar, press return (to navigate to the correct url) and the page will render then. But not on its own. Anyone experience this before?
I have tried changing the href to a different path to see if it is a problem with the target view/controller - it is not, happens to all of the paths I try. I have also tried different capybara drivers: :selenium, :chrome, :poltergeist. All same result!
Would love to provide more detail but i'm not sure what to show. Its a simple href and i'm not sure what could go wrong.
Cheers
EDIT:
turns out there was an error in the logs. Will update with a solution.
error:
Could not log "render_template.action_view" event. NoMethodError: undefined method `render_views?' for RSpec::ExampleGroups::LayoutsSplash::View:Class ["/Users/mitchellmeyer/.rvm/gems/ruby-2.3.1/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:732:in `method_missing'",
The error shown in the logs is a know rspec/rspec-rails 3.6 issue - upgrading will fix that. Beyond that, the fact it works when a URL is submitted manually to the browser but not when clicking on the link indicates the link is probably being interfered with by JS. Most likely that's Turbolinks which you can disable for a given link by adding a data-turbolinks=“false” attribute to the link. If that fixes the behavior (which you state it did) then it's probable you have a JS error in one of your files. Check the developer console in the browser for any errors shown and fix them.
Since you mention Poltergeist, as a driver you tried, in your question it's possible for there to be silent errors that cause JS to fail when using it since it doesn't support anything beyond ES 5.1 so it's not really that suitable for testing modern webapps any more and I would recommend sticking to headless chrome if you need headless testing.

Bxslider only works when refreshing the page

Why does bxslider not loading in the beginning but works when I refresh the page?
I already begin with $(document).ready(function(){});
I'm building it on Rails FYI.
https://photos4humanity.herokuapp.com/galleries
If you click on gallery, you will see a black page, then if you refresh it appears. Also it is not showing when I just click onto the link from the nav bar.
It should look like this
Ok, so after some troubleshooting, it's a rails specific situation. Turbolink that came with Rails prevented the site to reload. So download the jquery-turbolink gem will work.
JQuery gets loaded only on page refresh in Rails 4 application

Turbolinks causes a link with href="#" to trigger page refresh

I have a very simple link on my page. My link. It causes a page refresh. when I remove "turbolinks", it no longer causes a refresh.
I've used links with hash fragments all the time in the past. Unless I've missed something very fundamental for a long time, I don't understand how this can cause a refresh.
It does not have any JS event handlers attached to it.
Any ideas?
It may not matter, but I'm using jQuery, Twitter-Bootstrap, and Ruby on Rails.
Clues so far:
When I remove Turbolinks, the link behaves properly (does not cause page refresh).
Links with "#" as the URL cause a reload on every page of my app.
Links with any "#hasfragmenttext" will cause a single refresh and then the URL of the page is "mypage#hasfragmenttext", any additional clicks do NOT cause page refresh... hmm.
The above solution didn't work for me but this did :
My link
This can be found at https://github.com/turbolinks/turbolinks
update: This solution works for turbolinks 5, for classic turbolinks check the previous answer by #wael34218
Use data-no-turbolink attribute on that link the error should be gone
<a href="#" data-no-turbolink>My link</a>
With Rails 7 / Hotwire, you now need to use:
data-turbo="false"

Getting nested iframes with Facebooker in iframe app

Has anyone encountered nested iframes in their Rails/Facebooker application?
Basically, every time I click an action or link, the entire facebook page reloads inside my existing iframe, causing two (and more on each subsequent click) facebook borders to appear.
I've gone over the instructions three times and changed every setting imaginable, but the app still opens up in new facebook page inside the iframe. Any ideas anyone?
itonly appears when I use the
ensure_application_is_installed_by_facebook_user
filter, but if the user already has the application installed and I use the
ensure_authenticated_to_facebook
filter, it works fine...very strange (to me at least)
Turns out ensure_application_is_installed_by_facebook_user is deprecated because of a change in Facebook's API.
I plan to update the Facebooker documentation with this information soon.
I experienced the same thing with nested iframes, so I used "ensure_authenticated_to_facebook" instead. The only gotcha was that after the user installed the app, it would redirect them to my domain and not the facebook iframe page. After doing some tweaking in facebooker, I decided to hard code :canvas=>"true" in this method which is in lib/facebooker/rails/controller.rb line 189
def create_new_facebook_session_and_redirect!
session[:facebook_session] = new_facebook_session
next_url = after_facebook_login_url || default_after_facebook_login_url
#top_redirect_to session[:facebook_session].login_url({:next => next_url, :canvas=>params[:fb_sig_in_canvas]}) unless #installation_required
top_redirect_to session[:facebook_session].login_url({:next => next_url, :canvas=>"true"}) unless #installation_required
false
end
I wrote a tutorial on this fix in my blog - http://railsrant.com/2009/10/14/creating-a-facebook-iframe-app-using-ruby-on-rails-facebooker/

Resources