erb

ERB Template removing the trailing line

ε祈祈猫儿з 提交于 2020-01-01 07:52:05
问题 I have an ERB template for sending an email. Name: <%= @user.name %> <% if @user.phone.present? %> Phone: <%= @user.phone %> <% end %> Address: <%= @user.address %> I am trying to remove the blank line between Name and Address when Phone is empty. Returned result Name: John Miller Address: X124 Dummy Lane, Dummy City, CA Expected result Name: John Miller Address: X124 Dummy Lane, Dummy City, CA I have tried to use <%--%> tags(to remove the trailing new line) without any success. Name: <%=

ERB Template removing the trailing line

て烟熏妆下的殇ゞ 提交于 2020-01-01 07:51:26
问题 I have an ERB template for sending an email. Name: <%= @user.name %> <% if @user.phone.present? %> Phone: <%= @user.phone %> <% end %> Address: <%= @user.address %> I am trying to remove the blank line between Name and Address when Phone is empty. Returned result Name: John Miller Address: X124 Dummy Lane, Dummy City, CA Expected result Name: John Miller Address: X124 Dummy Lane, Dummy City, CA I have tried to use <%--%> tags(to remove the trailing new line) without any success. Name: <%=

How do I include HTML in a JS Rails response?

十年热恋 提交于 2019-12-31 14:53:34
问题 I have a FooController that responds to HTML and JS (AJAX) queries: # app/controllers/foo_controller.rb: class FooController < ApplicationController layout 'foo' def bar respond_to do |format| format.html # foo/bar.html.erb format.js # foo/bar.js.erb end end end The templates to support it: # app/views/layouts/foo.html.erb: <html>...<%= yield %>...</html> # app/views/layouts/foo.json.erb: <%= yield %> And an AJAX template in which I want to render a partial: # app/views/foo/bar.js.erb: dojo

Rails won't precompile .js.erb

谁说我不能喝 提交于 2019-12-31 06:12:45
问题 Why Rails won't precompile a .js.erb asset? My config/application.rb : require File.expand_path('../boot', __FILE__) require 'rails/all' Bundler.require(:default, Rails.env) module Sflitmap class Application < Rails::Application # these precompile OK config.assets.precompile += ['edge/edge.1.5.0.min.js', 'edge/ink-falling_edgeActions.js', 'edge/inkAnimationTrigger.js'] # this will not precompile config.assets.precompile += ['edge/ink-falling_edge.js.erb'] end end My config/environments

VIM: insert empty ERB tags

廉价感情. 提交于 2019-12-29 09:04:05
问题 How can I insert empty ERB tags and put cursor inside it? It is similar to surrounding with surround plugin, but there is nothing to surround. For example, from this: bla|bla I want get this: bla<%= | %>bla 回答1: I would use Tim Pope's surround plugin to accomplish this. Add the following to you ~/.vim/after/ftplugin/erb.vim let b:surround_{char2nr('=')} = "<%= \r %>" let b:surround_{char2nr('-')} = "<% \r %>" Now when you press <c-s>= it will insert <%= | %> just as you wanted. You may also

VIM: insert empty ERB tags

旧城冷巷雨未停 提交于 2019-12-29 09:03:16
问题 How can I insert empty ERB tags and put cursor inside it? It is similar to surrounding with surround plugin, but there is nothing to surround. For example, from this: bla|bla I want get this: bla<%= | %>bla 回答1: I would use Tim Pope's surround plugin to accomplish this. Add the following to you ~/.vim/after/ftplugin/erb.vim let b:surround_{char2nr('=')} = "<%= \r %>" let b:surround_{char2nr('-')} = "<% \r %>" Now when you press <c-s>= it will insert <%= | %> just as you wanted. You may also

Use ruby array for a javascript array in erb. Escaping quotes

走远了吗. 提交于 2019-12-29 07:37:32
问题 i've found numerous things online for this but they dont work for me. am i missing something. In my controller i have @t = ["a","b","c"] in the erb file that is 'callback' the @t renders like so: ["a", "b", "c"] i've done hacks to replace the " to proper ' symbols. I've read that to_json should work but it doesnt. The following does not work ["a","b","c"].to_json . The results are the same. 回答1: to_json is working fine. What you're running into is Rails 3.x's XSS protection. There's a good

rails database.yml not accepting ERB

假装没事ソ 提交于 2019-12-29 07:27:08
问题 In my database.yml, I have: staging: adapter: <%= ENV['DATABASE_ADAPTER'] %> encoding: <%= ENV['DATABASE_ENCODING'] %> database: <%= ENV['DATABASE'] %> host: <%= ENV['DATABASE_HOST'] %> port: <%= ENV['DATABASE_PORT'].to_i %> pool: <%= ENV['DATABASE_POOL'].to_i %> username: <%= ENV['DATABASE_USERNAME'] %> password: <%= ENV['DATABASE_PASSWORD'] %> However, it does not read the ERB part when actually booting puma: /usr/local/lib/ruby/gems/2.1.0/gems/activesupport-4.2.1/lib/active_support

Assets not being run though the .erb preprocessor

醉酒当歌 提交于 2019-12-29 07:11:28
问题 I am having trouble trying to rake assets:precompile in my rails 3.1 app. I keep getting the following error: rake aborted! Invalid CSS after "...und-image: url(": expected ")", was "<%= asset_path(..." It seems that the erb preprocessor is not being invokeb but my file is called style.css.scss.erb . Any suggestions? 回答1: Ruby documentation seems a bit unclear on a few things such as the usage of the asset_path and other such helper in stylesheets. Anyways this is what I did to get around the

Rails js.erb file cannot find method “render”

和自甴很熟 提交于 2019-12-27 14:54:28
问题 I've got the following code in a Javascript ERB file: $(document).ready(function() { $("#workout-week").append( <%= escape_javascript(render :partial => "show_training_period", :locals => { :period => @period }) %> ); }); When I got to the view, I get the following error: undefined method `render' for #<#<Class:0x00000004e21158>:0x00000005dbfe98> The partial exists, and the local variable is non-nil. Any idea why this might happen? Stack trace: app/assets/javascripts/slider.js.erb:2:in