Ruby on Rails Views. (Best Practice) - ruby-on-rails

This might seem like a strange question. But have been pondering over this for quite some time now.
Is it better to use RAW HTML in Rails views or to go with Rails view helpers??
If i understand correctly Rails views helpers are converted back to raw HTML. So would it affect the performance of the application by a great deal ??
And is there a tool that would allow me to convert HTML to ERB :)
I'm aware of the HTML to HAML converter.
Thank you,

Certainly better to use a rails helper, as this allows you to create dynamic elements

Use Rails helpers, they guarantee the latest HTML good practice are used and up to date.

Related

What do I need to do to convert the views in my Rails app from HAML to ERB?

I have a Rails app that I'm customizing. The more I work on it, the more I both love and hate HAML. I love that HAML's so clean to look at it, I hate that I can't intuitively trouble shoot with Chrome Inspector or Safari Developer Tools. So, I have gathered that conversion to ERB is the best thing for others in my shoes (designers or other mere mortals with basic knowledge of HTML and CSS, wanting to customize the content in this open source Rails app).
What are the steps involved in converting the views from HAML to ERB
and what else will I need to change? ...routes? controllers? anything?
There are a lot of the down-in-the-weeds questions about this, but I'm looking for an overview so I can wrap my head around what to expect.
If you're just converting HAML->HTML/ERB You shouldn't have any need to be changing any controllers, routes or models at all. But I wouldn't necessarily recommend taking that route. HAML is great because it stops people being syntactically incorrect in their HTML. It essentially forces you to not make mistakes.
I don't really understand the issue with troubleshooting through chrome/firefox as all it's outputting is HTML at the end of the day.

Site move to Rails - partials

I'm moving my site to Rails currently.
Beforehand I used jQuery load() method to insert a separate site html element. Now moving to Rails, I have to change it. From what I've learnt so far, the best way here is to use a Rails partial for this purpose.
Is this correct?
I would recommend taking a read through the Ruby on Rails Guides which are extremely helpful if you are just getting started in Rails. The specific section that might help is their documentation on using partials.
Yes, you are correct. Partials come in handy when you want to load some HTML elements conditionally, or want to reuse them in different places. A prime example for that is the footer or header of a website. Instead of writing the code in all the required files, simply render the partial wherever required. For further reading/implementation guide, you can refer the section on partials in the RoR guide

Pure HTML template solution for Rails?

I love HAML, however recently our projects have come under some scrutiny with regards to reliance on non-html structured templates. I thought I'd take it a step further by asking the question, "How can we use pure HTML design based templates in Ruby on Rails?"
The closest thing I've found so far is a very interesting project that has it's most recent update from 2010 called Kwartz from the author of Erubis.
Is there a project that upholds this pure HTML isolation for designers that is up-to-date and viable on Rails 3.2.x?
Your designers are correct that HAML does not have widespread HTML tool support.
A really excellent solution IMHO is Handlebars. It is simpler than HAML, and will work with more HTML tools because Handlebars emphasizes moving code out of the page template and into the controller. This also is good for writing maintainable pages with designers and also for security.
Handlebars is led by Yehuda Katz, who helped write Rails 3, is a core contributor to JavaScript, and is currently working on Ember.js which also leverages Handlebars.
http://handlebarsjs.com/
You are either going to do something with the templates, right? As in, the designer gives you the template, you strip out the parts that already belong to app/views/layouts/application, inject the necessary ruby to get your data into the view etc.
So what's the problem? Let the designers provide their templates in HTML, you convert them to HAML when using in the app, instead of converting them to ERB.

Printable content in Rails

i would like to create an application that needs to have the option to print things. I would like to ask if there is a standard way of handling such situations in Rails, or it's just a specific layout to be served when printing is asked. Is there a gem, or a good approach on doing such a thing ?
I'ved used the WickedPDF gem in the past with much success. It's based on wkhtmltopdf and what I really like about it is the PDF is generated based on a view template that's standard ERB (possibly HAML) and CSS.
It's better than going with prawn in my opinion as the template markup/styling can be reused for the PDF itself.

Logic free templates for Ruby on Rails

I am looking for a technique for moving Ruby on Rails methods and logic (<% if, link_to etc.) away from templates. So far I have been looking at the mustache template language, but I am not entire sure if this is the way to go.
Any thoughts? Would you recommend mustache or is there a better choice?
In addition to Mustache, there is Liquid (used by Shopify) and Radius (used by Radiant). You may want to check them out.

Resources