Each link_to application on my rail 4 is called twice

I am having unusual behavior with my Rails 4 Application. Every time I click the link_to link inside my views, my actions with controllers are called twice. For instance:

In my root_url , I have this standard call for users_profile :

 <%= link_to('User Profile', users_profile_path, :class => "logout-button") %> 

When I click this link, my console shows the following output:

 Started GET "/users/profile" for 127.0.0.1 at 2013-11-25 20:45:53 -0200 Processing by Users::SessionsController#profile as HTML User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = 45 ORDER BY "users"."id" ASC LIMIT 1 InvestorProfile Load (0.5ms) SELECT "investor_profiles".* FROM "investor_profiles" WHERE "investor_profiles"."user_id" = $1 ORDER BY "investor_profiles"."id" ASC LIMIT 1 [["user_id", 45]] EmployeeProfile Load (0.5ms) SELECT "employee_profiles".* FROM "employee_profiles" WHERE "employee_profiles"."user_id" = $1 ORDER BY "employee_profiles"."id" ASC LIMIT 1 [["user_id", 45]] Rendered users/sessions/_investor_setup.html.erb (3.9ms) Rendered users/sessions/profile.html.erb within layouts/application (5.2ms) Completed 200 OK in 19ms (Views: 11.2ms | ActiveRecord: 2.5ms) Started GET "/users/profile" for 127.0.0.1 at 2013-11-25 20:45:53 -0200 Processing by Users::SessionsController#profile as HTML User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 45 ORDER BY "users"."id" ASC LIMIT 1 InvestorProfile Load (0.3ms) SELECT "investor_profiles".* FROM "investor_profiles" WHERE "investor_profiles"."user_id" = $1 ORDER BY "investor_profiles"."id" ASC LIMIT 1 [["user_id", 45]] EmployeeProfile Load (0.2ms) SELECT "employee_profiles".* FROM "employee_profiles" WHERE "employee_profiles"."user_id" = $1 ORDER BY "employee_profiles"."id" ASC LIMIT 1 [["user_id", 45]] Rendered users/sessions/_investor_setup.html.erb (3.3ms) Rendered users/sessions/profile.html.erb within layouts/application (4.1ms) Completed 200 OK in 12ms (Views: 7.5ms | ActiveRecord: 1.2ms) 

People often have this behavior when there is a remote (e.g. JS) method call, but this is not my case. the weirdest part is if I put the direct url in users_profile_path in my browser. I get only one request in the rails console:

 Started GET "/users/profile" for 127.0.0.1 at 2013-11-25 20:48:17 -0200 Processing by Users::SessionsController#profile as HTML User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 45 ORDER BY "users"."id" ASC LIMIT 1 InvestorProfile Load (0.3ms) SELECT "investor_profiles".* FROM "investor_profiles" WHERE "investor_profiles"."user_id" = $1 ORDER BY "investor_profiles"."id" ASC LIMIT 1 [["user_id", 45]] EmployeeProfile Load (0.2ms) SELECT "employee_profiles".* FROM "employee_profiles" WHERE "employee_profiles"."user_id" = $1 ORDER BY "employee_profiles"."id" ASC LIMIT 1 [["user_id", 45]] Rendered users/sessions/_investor_setup.html.erb (3.4ms) Rendered users/sessions/profile.html.erb within layouts/application (4.2ms) Completed 200 OK in 12ms (Views: 7.7ms | ActiveRecord: 1.1ms) 

I get the same result for every link inside my application, not just that.

+6
source share
3 answers

If you want your application to still use Turbolinks, then " Failing Turbolinks " on code that gives you problems is the way to go; just add data-no-turbolink .

I'm having problems using Bootstrap 3 and adding a fix. For instance:

 <li class="list-group-item" data-no-turbolink> <%= link_to download_path(item) do %> <button type="button" class="btn btn-success">Download</button> <% end %> </li> 
+10
source

I really managed to solve it myself. There, by default, a stone that is installed with rails 4.0 is called Turbolinks * .

For some reason, the javascript used in this gem * caused double requests on my server. That's why only GET requests did this, and POST requests were normal. I still don't understand why gem * calls this, but after I removed the next line from my application.js file, the double requests stopped.

 =// require turbolinks 
+3
source

Another solution is to add data-no-turbolink to the tag.

More information here: http://blog.flightswithfriends.com/post/53943440505/how-to-disable-turbolinks-in-rails-4

+3
source

Source: https://habr.com/ru/post/958805/


All Articles