Not rendering Rails 4 partial correctly - ruby-on-rails

I've upgraded a Rails 3 app to 4 and I'm trying to render some really simple partial thats not working correctly.
I'm using HAML and I have a layouts folder with a application.html.haml file inside. Within this file I call several partials that make up the template for the entire page. these partials reside in a application folder. For instance, I call:
= render "chromeframe"
which works perfectly. However, below this I have:
`= render "header"
which contains a lot of haml html code for the header of the page. My problem is this isn't getting rendered correctly and all I'm getting from that call is"
<header id="header">
<h1>Dummy</h1>
</header>
Still fairly new to Rails but I had this working perfectly in Rails 3 so I'm totally thrown by this problem. Any suggestions, I'm sure it's staring me in the face.
Thanks

Looks like you have a dummy _header.html.xxx or header.html.xxx anywhere in your views, that is found by render. It doesn't have to be a haml file.
Look at your deveopment.log. It should say Rendered ...header... (xx ms).
It tells you, where the partial is found.

Related

Middleman render partial from absolute path

I'm writing a middleman extensions but having trouble re-using the render_partial method with an erb file path outside of the main application.
Trying to do so always gives me the error
Cannot locate partial ...
I believe this is because it only accepts relative paths from the application root.
Is there a way i can render partials with absolute paths in Middleman?
I can get around the issue by requiring Erb and doing my own rendering however I'm really keen to keep the Middleman Context when rendering my extension partials.
Any help greatly appreciated.
EDIT
It turn's out this is not currently possible with Middleman v4. This line of code will only resolve relative file paths.
My work around was to write my own mini helper class that utilises ERB to render partials from absolute paths. I was able to keep the Middleman template context by using delegates on the #app instance.
try using this instead of render_partial
<%= partial 'partial/yourpartialname' %>
where yourpartialname should be in the format of _yourpartialname.html.erb
Hope this helps :)

How to register rb as a template handler in rails

Well since I am using a lot of helper methods in my view files and I avoid using html in most of my view files.
Example
myview.html.erb
<%=myhelper #myobject%>
so I end up using,the erb processing tags each time for each file.
<%=%>
I want to register .rb as a template handler or any other extention for that matter.
So my templates look like
myview.html.rb
myhelper #myobject
I am clueless on how to go ahead.
I found it,it seems railscasts already covered that part.
Its show notes,worth checking out.
https://github.com/railscasts/379-template-handlers/blob/master/store-after/config/initializers/ruby_template_handler.rb
Things without ruby are easy to read and render without those erb tags.

Where does HAML load its templates from?

I am dabbling in some existing code and I am able to render some HAML like this:
.content_container
%strong{:class => "code", :id => "message"} Hello World!
But when the page loads, this HTML is rendered in an existing layout with a lot of the elements already defined.
I looked in config/settings/environment.rb which I was suggested to do by a HAML tutorial, but there was no mention of any other HAML code there.
Any idea how I can overwrite the header or find where the template is predefined?
It sounds like the template is being rendered with a layout. look in <app_root>/app/views/layouts/ for your missing HTML.
HAML likes files in the views directory that have a haml extension.
The docs say:
...all view files with the ".html.haml" extension will be compiled using Haml.

Ruby questions about web layer layout

I am trying to make a URL like Link Title from within my application. What is the file that I need to edit to link this URL to a controller and then a view?
Also, I am still working my way through this tutorial:
http://guides.rubyonrails.org/layouts_and_rendering.html
and I am wondering when they do something like this:
<%= stylesheet_link_tag "http://example.com/main.css" %>
is that supposed to live in the application.html.erb file or the index.html.erb file?
What is the file that I need to edit to link this url to a controller and then a view?
routes.rb
See the rails guide
is that supposed to live in the application.html.erb file or the index.html.erb file?
The simple answer is: application.html.erb, inside the head section. There are ways of injecting view template stuff into the head, but if you're just starting out, stick with application.html.erb.

Display html file inside iframe

How to display a HTML file from my system in iframe using rails?
I will explain my issue...
I have a view file that has an iframe which calls an action through <iframe src="controller/action?param=somevalue"></iframe> and the action renders a HTML file based on the params.
The HTML file called has reference to stylesheets and javascripts in the format <script type="text/javascript" src="../common/About.js"></script>
When viewed in browser the HTML file displays correctly with the styles and javascript but when viewed in the application the styling and scripts are not working from the external file. On viewing the source code for the external files i get "Unknown action" error.
What is that i am doing wrong in this?
(reacting to yr last comment): you need to specify css and js files in the iframed html page separately. html in an iframe is rendered completely independent from the surrounding page.
This is not a rails-related question imho.
I found the mistake I made. Its because of routes being not defined properly. When I give relative urls in the html file, the rails views assumes the full path to be some thing like src="controller/common/About.js". As there is no action defined by the name common I was getting the Unknown action error. I have redefined my routes and its working fine now.

Resources