How can I get haml to recompile in rails? - ruby-on-rails

I added a div to my haml file:
%section.splunk
.splunk_results Loading splunk data...
that will later be populated by an ajax call. However, it isn't showing up in my html file, even when I restart rails and navigate to that page. My research showed that it should auto-compile when I load the page -- why isn't this so?
EDIT:
The haml file is located at myAppName/client/order_details.haml. The HTML that it should be presumably compiling to is in myAppName/public/templates/order_details.html.

HAML files get interpreted as HTML files using the asset pipeline, which requires that your file be in app/assets.
Additionally, the controller action specifies the file that will be rendered. Take a look at your Rails logs to see what file the action is actually rendering.

Related

Why naming convention of views files in rails are considered as action.html.erb only?

Why naming convention of views files in rails are considered as action.html.erb only ( instead of action.erb.html ) ?
What will happen if we write views files as action.erb.html ?
What will happen if we write views files as action.erb.html?
The first thing that will happen is that the Ruby syntax highlighting in your editor will stop working as the file extension is now .html instead of .erb. On almost every file system in use the file extension is the rightmost part of the file name.
The second thing that will happen is that Rails will no longer be able to lookup the template and even if it could it would no longer process it through ERB as it no longer has the .erb file extension.
.html is just a segment of the file name that lets the rails template resolver distinguish between templates for different formats when looking up a template for a given request format. Its not really technically part of the extension. For example:
show.html # just HTML - no processing
show.html.erb # a HTML ERB template
show.html.slim # a HTML Slim template
show.html.haml # a HTML Haml template
show.xml.erb # a XML ERB template
show.xml.slim # a XML Slim template
show.xml.haml # a XML Haml template
show.json.erb # a JSON ERB template
show.json.jbuilder # a JSON jBuilder template
TRDL; changing the file extension is a dumb idea. Especially when you consider that Rails actually supports multiple template engines such as jbuilder, Slim and Haml in addition to ERB.

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.

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.

Getting SASS to generate CSS files from multiple directories

Fairly new to Rails. I am implementing a wholesale homepage redesign on a Rails site. For the time being, we will push the redesigned home page but leave the rest of the site as is. Later, we will port the rest of the site to the new design.
I would like to create a "branch" of the CSS inside the current project that is loaded only by the home page. We use SASS to generate the CSS. The file layout:
/public/stylesheets: #Generated CSS for rest of site
/public/stylesheets/sass: #SASS source files for rest of site
/public/stylesheets/v3: #Desired location for CSS for home page
/public/stylesheets/v3/sass: #SASS source files for new-style home page
The controller for / calls render :layout => 'v3', and this layout contains:
!= include_stylesheets :common_v3, :media => "all"
Here's the relevant section from assets.yml:
stylesheets:
common:
- public/stylesheets/reset.css
- public/stylesheets/*.css
common_v3:
- public/stylesheets/v3/reset.css
- public/stylesheets/v3/*.css
Could someone help me figure out how to make SASS generate the new CSS files? If I put a new file in /public/stylesheets/sass, the corresponding CSS file is created, but the v3 dir is ignored.
I tried the following in environment.rb, but it's not working.
Sass::Plugin.options[:template_location] = %W( #{RAILS_ROOT}/public/stylesheets/sass #{RAILS_ROOT}/public/stylesheets/v3/sass )
Using Rails 2.3.8 with Haml 2.2.2.
First, upgrade Haml/Sass to the latest version (3.0.24).
Now you can use the Sass::Plugin.add_template_location method to tell Sass where your templates are. For example:
Sass::Plugin.add_template_location("#{RAILS_ROOT}/public/stylesheets/v3/sass",
"#{RAILS_ROOT}/public/stylesheets/v3")

html.erb vs erb (and haml equivalents)

I'm not sure I understand the difference between html.erb or haml.erb files and .erb files in the views for a Ruby on Rails application.
What are the dis/advantages of each (html.erb/haml.erb or .erb/.haml) files?
PS I'm not asking about the difference between the erb and haml files -- just appending the extension to an html file versus not appending it.
Mainly this is about content-type and if you have any respond_to blocks in your controller. If you declare your file with a .html.erb or .haml.erb extension you are reducing the scope of response that those files can be used, which will only be served if the request is for the mime type. When using only .erbyou expand the usability of your file, not restricting it's response type.

Resources