Question

When requesting a page from rails I get strange behaviours.

Calling on <%= link_to "Start »", '/app', role: "button" %> the first time will get me to the view without loading ANY asset except for one js file included at the bottom of the layout (after </body>). This results in an ugly und functional page.

Started GET "/app" for 10.0.2.2 at 2014-05-08 16:09:51 +0000
Processing by AppController#index as HTML
  User Load (0.4ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
  Authentication Load (0.2ms)  SELECT  "authentications".* FROM "authentications"  WHERE "authentications"."user_id" = $1  ORDER BY "authentications"."id" ASC LIMIT 1  [["user_id", 1]]
  Rendered app/_google_maps.html.erb (11.3ms)
  Rendered app/index.html.erb within layouts/application (45.9ms)
Completed 200 OK in 886ms (Views: 129.4ms | ActiveRecord: 2.7ms)


Started GET "/assets/app.js?body=1" for 10.0.2.2 at 2014-05-08 16:09:52 +0000

Calling it the second time will get the results I would normally expect - loading the page with all its elements.

Started GET "/app" for 10.0.2.2 at 2014-05-08 16:10:56 +0000
Processing by AppController#index as HTML
  User Load (0.3ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
  Authentication Load (0.2ms)  SELECT  "authentications".* FROM "authentications"  WHERE "authentications"."user_id" = $1  ORDER BY "authentications"."id" ASC LIMIT 1  [["user_id", 1]]
  Rendered app/_google_maps.html.erb (13.7ms)
  Rendered app/index.html.erb within layouts/application (35.3ms)
Completed 200 OK in 561ms (Views: 111.4ms | ActiveRecord: 0.9ms)


Started GET "/assets/bootstrap.min.css?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/jquery.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/app.css?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/application.css?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/bootstrap-slider.css?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/font-awesome.min.css?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/bootstrap.min.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/jquery_ujs.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/turbolinks.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/bootstrap-slider.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/application.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000


Started GET "/assets/app.js?body=1" for 10.0.2.2 at 2014-05-08 16:10:57 +0000

What am I missing here?

Was it helpful?

Solution

As Michael suggested in the comments it was a turbo link. So, what I did was adding data-no-turbolink=true to the anchor like so: <%= link_to "Start »", app_path, data: { no_turbolink: true } %> - that solved my problem.

Edit:

Better solution: <body data-no-turbolink=true>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top