Questions tagged [erb]

ERB is a simple templating system for Ruby, embedding code in any plain-text document. It is often used for HTML generation in web frameworks (such as Ruby on Rails).

ERB stands for Embedded Ruby and is a markup-based way of embedding Ruby code into text files.

The tag may be used for the standard (pure-ruby) ERB library, the C-based implementation eRuby or the even-faster Erubis library. ERB ships with Ruby installations as part of the Standard Library; the documentation for ERB is available on ruby-doc.org.

ERB is commonly used as templating system, for example in producing HTML pages with dynamic content (such as in the Ruby on Rails web framework) but is also useful in a variety of other contexts, such as code generation, mass emailing, or simple text reporting.

ERB markup is generally seen as <% ... %> and <%= ... %>. See the section "Recognized Tags" in the documentation for the ERB class for the full set of markup.

A simple example:

template.erb

Hello, <%=name%>. Are you:
<% moods.each_with_index do |mood,i|%>
  <%=i%>. <%=mood%>
<% end %>

code.rb

require 'erb'
template = ERB.new(IO.read('template.erb'))
name = "Phrogz"
moods = %w[ Happy Angry Sad ]

message = template.result(binding)
puts message

#=> Hello, Phrogz. Are you:
#=> 
#=>   0. Happy
#=>   1. Angry
#=>   2. Sad
2617 questions
0
votes
1 answer

Unable to clear text field with overridden submit method used for ajax implementation via Jquery 1.4

I have a functionality of posting messages to a group which works using AJAX via Jquery. When I click on the "Post" button which is the value of the submit_tag, javascript is rendered and the page without reloading displays the latest message…
boddhisattva
  • 6,908
  • 11
  • 48
  • 72
0
votes
1 answer

Query select elements everytime partial is loaded by Vanilla Javascript in Rails

I have a partial inside a partial which has radio buttons or check boxes. What I want to do is to get the radio button or checkboxes which are clicked. Now initially when the page is loaded I am able to get the buttons but when I go to the next…
Lax_Sam
  • 1,099
  • 2
  • 14
  • 32
0
votes
3 answers

Ajax functionality seems to fail when on adding a div tag to my .js.erb file

I am doing some styling in my code where I want to display the time a message is posted on a groups forum in my app. Currenlty posting of every message in this forum works with AJAX functionality implemented via Jquery 1.4. On including the div tag…
boddhisattva
  • 6,908
  • 11
  • 48
  • 72
0
votes
2 answers

How to compress the html.erb file by removing white spaces?

How to remove comments and white spaces in html.erb files while deploying to production System configuration Rails version: 6.0.0 Ruby version: 2.6.1
0
votes
1 answer

wice_grid (ruby on rails): ERB to SLIM

I'm using the wice-grid gem. Their examples show the views in .erb but I'd like to use .slim for my project but am having trouble converting the example erb into working slim. # ERB renders and works perfectly <%= grid(@tasks_grid) do |g| …
yzi0148
  • 45
  • 1
  • 6
0
votes
1 answer

Pop up only functions as intended the third time I open it?

I have a pop up I am making thats intended function is to open with interactive calendar Which allows the User to input a Start date and End date using jquery datepicker. However currently on page load, I have to open and close the pop up twice…
JBDR
  • 55
  • 4
0
votes
1 answer

How can I force js.erb to refresh Ruby code

I'm trying to get a list of the data_file_names for my XslSheet model into a select dropdown in my js.erb file. I've tried the following in input.js.erb: inputEx.registerType("button", inputEx.ButtonField, [ { type: "select", label:…
Daniel Lawton
  • 416
  • 3
  • 9
  • 30
0
votes
1 answer

Simple search form is not working in rails

I'm following Railscast: http://railscasts.com/episodes/37-simple-search-form?autoplay=true The result shows well in my implementation. But because I have first_name and last_name columns instead of just "name" as in the example above, I need a way…
superbot
  • 401
  • 3
  • 19
0
votes
0 answers

Rails form for nested object w/ user inputed key values

I have a model for Experiment and the schema looks like this: create_table "experiments", id: :serial, force: :cascade do |t| t.string "name" t.string "state" t.jsonb "experiment_conditions" end As you can see in the schema,…
Steez
  • 219
  • 5
  • 17
0
votes
1 answer

How to embed a .yaml.erb into another .yaml.erb while keeping indentation?

Suppose I have two files, parent.yaml.erb and and child.yaml.erb and I would like to include the contents of child.yaml.erb inside of parent.yaml.erb and calculate it in context of parent.yaml.erb. Example: parent.yaml.erb: name: parent first: …
Timur Nugmanov
  • 803
  • 9
  • 16
0
votes
2 answers

ERB isn't interpreting variables correctly

What I'm trying to do here is to create a markdown template that allows erb too. I came with this solution: class MarkdownTemplateHandler def call(template, source) markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML) …
rwehresmann
  • 1,108
  • 2
  • 11
  • 27
0
votes
1 answer

Wrong image url is passed for one form and correct to another form from partial in Rails 4

I am using a partial that is rendered in two forms belonging to two different controllers as below: update_user.html.erb <%= form_with model: @user, url: { controller: :profile, …
Lax_Sam
  • 1,099
  • 2
  • 14
  • 32
0
votes
1 answer

Rails 5 erb doesn't escape html

In a rails 5.2.3 erb template: <% input = "" %>

<%= input %>

is showing instead of >.. etc Isn't <%= ... %> supposed to prevent against reflected xss attack? Same issue if input is…
rigyt
  • 2,219
  • 3
  • 28
  • 40
0
votes
1 answer

Deep hiera lookup in a ruby template returns last result only

I have the following hiera: profile::example::firewalls: - serverclass1: label: http port: 80 label: https port: 443 - serverclass2: label: ssh port: 22 label: telnet port: 21 I try to call it in the following…
keeer
  • 783
  • 1
  • 5
  • 11
0
votes
1 answer

<% if !current_page?(action: 'edit') %> error . No route matches {:action=>"edit", :controller=>"…"}

My _footer.html.erb is (simplified):
Greg
  • 2,359
  • 5
  • 22
  • 35
1 2 3
99
100