I was using controller.controller_name and url_for to highlight various items in a menu bar in my rails app. This worked locally, but once I pushed to Heroku, I was finding that the same menu item was always being highlighted no matter what page I was on, and it was because url_for and controller.controller_name never change even when I go to other views. Why might this be happening. Could this be related to turbolinks? I'm confused because I thought turbolinks was only related to my front end...?
I just ran into this issue and found out it was due to caching the rendered menu.
Related
I am creating an embedded app for shopify in Ruby on Rails. And I came across a quick issue which I don't think should be a major one but I am not able to get it working so I was hoping if anyone could help me out.
Let me explain the issue.
What I have done
I have rendered a template where there are some contents and links to other controller which in return should render some other templates.
I have managed the routes properly.
The link that I have added is link this
link_to "Automatic Install", '/greetings', :method => :get
So the problem is when I click the link it loads a blank page inside the shopify iframe not rendering the proper template file associated to Greetings controller.
Same thing works for normal rails app but when i do the same for the rails application which is an embedded app for shopify it is not working as expected.
This really should be due to the app being loaded on iframe as shopify loads the embedded application on iframe. Which is why it may not be working.
I couldn't find any way of make it work but i strongly believe that there should be some proper way of doing it for the embedded app.
I hope someone could help me out here or point me to a right direction.
I started my journey with Rails and Ruby a couple of days ago and so far it is going well and I'm loving it!
Though, I do have a minor concern that I cannot find a solution to. I've had a minor sneak peek on turbolink and how that is embedded with Rails. But, my question (problem?) is that whenever I import/include an image (which is located in app/assets/image) with Rails image_tag(...), that image is reloaded whenever I redirect to another page. But if I use <img src="..." whereas the src is an extern link (image fetched from another page) it is not being re-fetched (meaning, it's cached when I redirect to another page).
So my question is: is there a special way to apply turbolink to image_tag?
Thanks.
This is because you are running in development mode. Rails uses an "Asset Pipeline. When in development environment it reloads the assets.
When you come to production, you will see the difference.
You can read more about it here: http://guides.rubyonrails.org/asset_pipeline.html
I can't seem to find a similar issue
On my website I am running into an issue where the browser progress bar will not show until the page is completely rendered.
This is particularly bad on a very slow page (which I am working on). It makes it look like the link may have been broken instead of just taking a little while.
Looking at the network
There is a GET method on the current page which returns a 304, this runs for about 3-5 seconds.
Once that finishes the new website will load with a near instant progress bar.
I am not sure what code I can share since this is happening everywhere on my site, it is just more noticeable on certain pages.
To see it at its worse go to http://www.swtorconquest.com/conquestweeks and click either "The Trade Emporium" or "Clash in Hyperspace".
I am having this issue both when testing locally and when the site is deployed.
I am using ruby 2.1.2 and rails 4.1.5
Do one thing, in application.html.erb, in body tag add this, it will solve your problem
<body data-no-turbolink>
The problem will almost certainly be Turbolinks, although this is just a guess. Lacking any other answers, I'll hopefully be able to give you some ideas:
When you load a page with Turbolinks, it will actually load the <body> tag of the page through Ajax, leading the <head> intact.
This causes a lot of problems if not handled correctly, one of which (we've found) being that your browser can no longer determine how quickly the page is loading. This is likely what your problem is.
Although I don't have an outright fix, I do have a test.
You can try removing any references to Turbolinks throughout the various pages in this part of your application. This can be done by using the following:
#app/views/layouts/application.html.erb
<%= javascript_include_tag "application" %> => remove the turbolinks reference
<%= stylesheet_link_tag "application" %> => remove the turbolinks reference
Also, you need to remove Turbolinks from your Gemfile & your application.js:
#app/assets/javascripts/application.js
//= require turbolinks => remove this line
This will give you the ability to gauge whether it's turbolinks which is preventing the status bar from loading correctly. If it is, then you'll have to work around this (I don't have any remedies off hand)
It must be noted that this test will not speed up the load time - it will merely show whether the status bar issue is caused by Turbolinks or not
When I click on a link and move to a new page, my form doesn't submit.
It works normally if I refresh though. It also works normally after disabling Turbolinks.
How can I resolve this and keep using Turbolinks?
jquery.turobolinks gem sorted out a similar issue i was having. Just make sure you include it directly after jquery.
It just makes all your js bindings etc still work with turbolinks
I am trying to cache a partial which is rendered in a layout. This partial is computationally expensive so I only want to compute it once. It is not controller specific so the usual fragment caching doesn't seem to apply. I decided to use Rails.cache.fetch('menu') for the caching instead. Here is what the contents of the partial look like.
<% Rails.cache.fetch('menu') do %>
Partial code...
<% end %>
But when I do this it renders the partial twice. For some reason it stopped doing this in my development environment so I decided to try and deploy it. I am not so lucky with my production environment. The partial itself generates a menu that includes links to a lot of the records in the site to help improve navigation.
I originally tried putting the cache statement in the layout file but then it was rendering the layout twice.
I recently added a jQuery hack to remove the duplicate html so that it kinda "works" for now, but I would rather get it working properly. I don't want to go to the trouble of installing some complicated caching system such as Redis, that requires me to run another server program. That would be overkill for the task. There must be something in rails that is well suited to caching parts of layouts.
Should I try something completely different or is this a bug in rails? If it is a bug then is there a workaround I can use?
I figured it out. Instead of caching the partial in the view, I created a helper method that returns the rendered partial.
#Returns a menu for the application layout
def menu
Rails.cache.fetch('menu') { render :partial => 'all/menu' }
end
Then all I needed in the layout is this line
<% menu %>
Try clearing your production cache. Chances are you had a logic error that was causing it to render twice. In development, the cache is usually disabled so that's why when you fixed the problem it went away in development. If you have redeployed, the issue is probably gone from the production code as well, but if the cache has not been cleared, it will keep displaying the cached logic error.