erb

Where is Ruby's ERB format “officially” defined?

非 Y 不嫁゛ 提交于 2019-12-21 03:37:06
问题 A number of sources (e.g. What is the meaning of erb? and three out of the top four results from this google search) cite http://ruby-doc.org/stdlib-1.8.7/libdoc/erb/rdoc/ERB.html as the official documentation on the ERB format, but that really just gives you the API rather than the file format. I found a nice little summary in http://docs.puppetlabs.com/guides/templating.html#erb-template-syntax, but there's got to be something more official, right? And who is the "defining authority"? Did

How to implement erb partials in a non rails app?

断了今生、忘了曾经 提交于 2019-12-20 12:38:56
问题 I want to do something like this: require 'erb' @var = 'test' template = ERB.new File.new("template.erb").read rendered = template.result(binding()) But how can I use partials in template.erb? 回答1: Perhaps brute-force it? header_partial = ERB.new(File.new("header_partial.erb").read).result(binding) footer_partial = ERB.new(File.new("footer_partial.erb").read).result(binding) template = ERB.new <<-EOF <%= header_partial %> Body content... <%= footer_partial %> EOF puts template.result(binding)

How to set html on data-disable-with to rails submit_tag

不羁岁月 提交于 2019-12-20 11:22:40
问题 I have a RoR app using bootstrap. I'm trying to apply the fontawesome html icon tag to a submit_tag helper, but it does not seem to be supported. When I click submit, the disable content just appears as a string instead of being interpreted to html, though it does for link_to helper. Here's the erb: <%= form_tag("/home/search", method: "get", class: "form-inline", role: "search", remote: true) do %> <div class="form-group"> <%= text_field_tag(:term, nil, {:class => "form-control", "data-html"

Vim html.erb snippets?? snipMate Need a vim tip

孤者浪人 提交于 2019-12-20 10:35:03
问题 When I'm in an html.erb file, I get no snipMate snippets. I would like both HTML and Ruby, or just HTML would be fine, How would I do this? Would I need to write a set of snippets? If so, is there a way of pulling in existing snippets without copying them? Is there a way of telling vim to go into html mode when it sees .html erb? 回答1: Snippets are stored in directory called snippets somewhere in your ~/.vim folder. If you look there, there is usually one file per filetype, there is a c

Tilt (kramdown) preventing ERB processing when rendering markdown

只愿长相守 提交于 2019-12-20 04:51:48
问题 I am building a website with Middleman. I am storing a lot of information in data files, as I am going to use the same information on multiple pages. (Partials wouldn't work for me, as same text from data can be used with different HTML tags or be slightly modified for different pages.) I want to write markdown in data files and then use it within HAML templates for specific pages. When I try to create relative links to other pages while using a reference to other data file, resulting HTML is

embedded ruby syntax “<%= .. %>” in rails [duplicate]

落花浮王杯 提交于 2019-12-20 03:09:25
问题 This question already has answers here : What is the difference between <%, <%=, <%# and -%> in ERB in Rails? (7 answers) <% %>(without equal) in ruby erb means? [duplicate] (3 answers) Closed 5 years ago . Am I correct with the idea below regarding ERB template? any advice would be really appreciated. Is the embedded ruby syntax with an equal sign "<%= %>" intended to render some output? while the one without the equal sign "<% %>" doesn't. 回答1: When you use <%= %> you render the expression

link_to() in Rails flash

怎甘沉沦 提交于 2019-12-19 05:24:38
问题 When a user fails login on my Rails app, I'd like to point them to a password reset page: flash[:notice] = "Login failed. If you have forgotten your password, you can #{link_to('reset it', reset_path)}" However, I can't use link_to in a controller. What's the best way to do this without mixing controller and view logic? My best guess is that the flash is the wrong place to do this, but I'd appreciate any input. 回答1: I think the most common solution is to stick a link to the password reset

Wrong number of arguments?

吃可爱长大的小学妹 提交于 2019-12-18 21:50:39
问题 I'm following Michael Hartl's tutorial here and am trying to create an index of users. My code: class UsersController < ApplicationController before_filter :signed_in_user, only: [:index, :edit, :update] . . . def index @users = User.all end . . . end and <%= provide(:title, 'All users') %> <h1>All users</h1> <ul class="users"> <% @users.each do |user| %> <li> <%= gravatar_for user, size: 52 %> <%= link_to user.name, user %> </li> <% end %> </ul> I've made sure my code matches the code in the

Rails - override <head> page element when using a partial or a specific controller view

瘦欲@ 提交于 2019-12-18 12:29:09
问题 Is there a way to append or override the <head> page element inside a rails view? Suppose I have something I only want to include in a particular view's <head> , and I am using the application.html.erb in order to render the rest of my views. In this case I do not want to discard application.html.erb but instead just append to it's head element for one particular page and nothing else. 回答1: In your application.html.erb : <head> <% if content_for? :for_head %> <%= yield :for_head %> <% end %>

Convert existing html.erb to Haml [closed]

空扰寡人 提交于 2019-12-18 10:15:13
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I have a rails project, the views only consist with HTML.ERB files, my client wants to convert ERB to HAML. I have too many views file. It's taking a huge amount of time to convert file by file. So that any simply way I can convert HTML to haml? I installed haml plugin under my project. 回答1: There you go: http:/