How do I execute ruby template files (ERB) without a web server from command line?

You should have everything you need in your ruby/bin directory. On my (WinXP, Ruby 1.8.6) system, I have ruby/bin/erb.bat erb.bat [switches] [inputfile] -x print ruby script -n print ruby script with line number -v enable verbose mode -d set $DEBUG to true -r [library] load a library -K [kcode] specify KANJI code-set -S [safe_level] set … Read more

Rails: access controller instance variable in CoffeeScript or JavaScript asset file

a couple of ways I have done this in the past put the data in hidden fields, access the data in js/coffee # single value <%= hidden_field_tag “foo_name”, @foo.name, { :id => “foo-name” } %> $(‘#foo-name’).val(); # when the ‘value’ has multiple attributes <%= hidden_field_tag “foo”, @foo.id, { :id => “foo”, “data-first-name” => @foo.first_name, “data-last-name” … Read more

What is the difference between .erb , .rhtml and .html.erb?

Nothing, really. It’s just a change of philosophy between Rails 1 and Rails 2. Before Rails 2, you had file.rhtml, file.rxml and file.rjs. In Rails, that changed to file.content_type.template_engine. So with file.html.erb, the content type is html and the template engine is ERb. rxml is now xml.builder and rjs should now (mostly) be js.rjs In … Read more