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.
Related
This is what I'm currently using:
haml :login_signup, :layout => :'main'
From the login_signup haml file, I would like to pass the name of the JS file to be parsed inside the :main haml file.
Reason? layout main.haml contains jquery reference. Rest of the haml files use different JS scripts that require jquery to be sourced first.
What you describe sounds like content_for.
Here is how this works add something like this to your main (source):
= yield(:somejs)
And then fill it from the login_signup view:
- content_for(:somejs) do
= javascript_include_tag :foo
Since you tagged also Sinatra there is a plugin for that functionality: https://github.com/foca/sinatra-content-for
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.
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.
https://gist.github.com/2597515
Note I used a html to haml converter. The sidebar partial is overlapping the main container, and the padding is messed up in some areas. Could this be because of my haml? Let me know.
Thanks!
It could definitely be because of your Haml code. The converter is not perfect and will never be perfect. You'll have to check the generated code by hand.
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.