erb

How can I convert html.slim to html.erb?

时光毁灭记忆、已成空白 提交于 2019-12-18 05:54:01
问题 I have many html.slim files that I would like to convert into html.erb files since I am not familiar with the slim syntax. Is there a converter for slim to erb? I found a converter for html to slim that has the functionality I am looking for but it does not do slim to erb. http://html2slim.herokuapp.com/ 回答1: Use Slim::ERBConverter from slim itself , there is also a command-line tool slimrb, see http://rdoc.info/gems/slim/frames for more documentation. 回答2: try the slimrb utility... slimrb -

Rails button_to - applying css class to button

南楼画角 提交于 2019-12-18 05:27:38
问题 This is silly, but I just can't figure out how to style the input element created by Rails button_to -- and yes, I've read the docs over and over again and tried the samples. Here's my ERB code: <%= button_to "Claim", action: "claim", idea_id: idea.id, remote: true, class: 'btn btn-small' %> And this yield the following HTML: <form action="/ideas/claim?class=btn+btn-small&idea_id=4&remote=true" class="button_to" method="post"> <div> <input data-remote="true" type="submit" value="Claim">

rails page titles

梦想与她 提交于 2019-12-17 22:07:46
问题 I don't like the way rails does page titles by default (just uses the controller name), so I'm working on a new way of doing it like so: application controller: def page_title "Default Title Here" end posts controller: def page_title "Awesome Posts" end application layout: <title><%=controller.page_title%></title> It works well because if I don't have a page_title method in whatever controller I'm currently using it falls back to the default in the application controller. But what if in my

Is there a way to use a Ruby loop inside of HAML's :javascript region?

扶醉桌前 提交于 2019-12-17 19:58:32
问题 Inside of HAML, can we have a loop inside the :javascript region? This will work: - 10.upto(20) do |i| :javascript document.getElementById('aDiv').innerHTML += '#{i}'; and this will not: :javascript - 10.upto(20) do |i| document.getElementById('aDiv').innerHTML += '#{i}'; can the code above also be made to work as well? 回答1: this one works %script - 10.upto(20) do |i| document.getElementById('aDiv').innerHTML += '#{i}'; 回答2: %html %head :javascript var foo = []; #{ limit = rand(4)+3 array =

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

萝らか妹 提交于 2019-12-17 17:52:06
问题 I need ERB (Ruby's templating system) for templating of non-HTML files. (Instead, I want to use it for source files such as .java, .cs, ...) How do I "execute" Ruby templates from command line? 回答1: 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]

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

我的梦境 提交于 2019-12-17 17:51:08
问题 I need ERB (Ruby's templating system) for templating of non-HTML files. (Instead, I want to use it for source files such as .java, .cs, ...) How do I "execute" Ruby templates from command line? 回答1: 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]

Block comments in html.erb templates in rails

有些话、适合烂在心里 提交于 2019-12-17 17:24:24
问题 How do you comment out html mixed with ruby code? some text <% ... %> more text <%= ... %> something else <% ... %> In jsp it's real simple: <%-- ... --%> , but I'm unable to find any concise option in rails. Simple html comments <!-- ... --> do not work: ruby code is still executed and yells errors. There's an option to use if false with html comments, but it's quite verbose, not to mention IDEs doesn't support it. There's also an option coming from pure ruby, which surprisingly works. <%

What is the meaning of erb?

假如想象 提交于 2019-12-17 10:12:43
问题 Why is the view of Rails application in the format *.erb.html ? What does "erb" mean? 回答1: erb stands for "Embedded RuBy". A .html.erb or .erb.html file is HTML with Ruby code embedded in; Rails will evaluate the Ruby to add content to the file dynamically, and will output a "pure" HTML file for rendering. 回答2: As @Chowlett mentioned before, erb stands for Embedded Ruby . When you define any file as ".html.erb" that means it's an HTML file with ruby code embedded in it and it is similar to "

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

心已入冬 提交于 2019-12-17 08:31:43
问题 In Rails 3.1 it is not possible to access controller instance variables in an asset js.erb or coffee.erb file using syntax such as <%= @foo %>, where @foo is set in the controller. So then the question is what are the best ways for passing controller variables to CoffeeScript or JavaScript assets. This question has kind of been asked in multiple convoluted forms on the forum, but my point in asking it again is to have a place where all recommendations are gathered together, and the code

Disable HTML escaping in erb templates

时光毁灭记忆、已成空白 提交于 2019-12-17 05:05:12
问题 In a Rails 3 application I have a domain class where one attribute stores pure HTML content (it's a blog app, the domain class is Post). In the ERB templates, I need to display the content of the attribute as it was formmated, with the HTML tags in place. But, Rails is escaping all HTML tags! How can I disable this behaviour for this class attribute? Example: somePost = Post.new somePost.content = "<strong> Hi, i'm here! </strong>" In the erb template: <%= somePost.content %> The HTML