erb

Loading .coffee files via a view in Rails

左心房为你撑大大i 提交于 2019-12-11 01:55:22
问题 My controller is as follows: class CommentLoaderController < ApplicationController respond_to :js def show puts 'here' @client_id = params[:id] respond_with @client_id end end It loads a .js file which has some .erb markup in it. I'd like to load a CoffeeScript file, compiled to JS on the fly. Is this possible with Rails 3? 回答1: I think this blog post that one of my colleagues wrote today might help http://www.storm-consultancy.com/blog/development/random-bits/todays-gotcha-when-coffeescript

Replace properties in one file from those in another in Ruby

ⅰ亾dé卋堺 提交于 2019-12-11 00:37:39
问题 I want to replace properties in one file from those in another. (I am new to ruby, and read about Ruby and YAML. I have a Java background) Eg. File 1 server_ip_address=$[ip] value_threshold=$[threshold] system_name=$[sys_name] File 2 ip=192.168.1.1 threshold=10 sys_name=foo The ruby script should replace the $ values by their real values (I do not know if $[] is the format used in ruby. Also do Files 1 and 2 have to be YAML files, or erb files?) and produce File 1 as : server_ip_address=192

Create method in html.erb file

微笑、不失礼 提交于 2019-12-10 17:54:26
问题 I have to create one method in file say 'myCode.html.erb'. I have to write ruby code with html. So far I came to know how to write method and call that method as below. method creation <%def helo print "This is function" end%> <%=helo%> #calling method But I'm in dilemma about how to write method in which I have to write both ruby and html code. Below is my code which I need to write in method. <% actions.each{ |action| tc = [] bizA = [] testcaseName = '' bizActionName = '' @factory.testcases

Rails 4.1.6 Asset pipeline not loading assets and javascript in production

允我心安 提交于 2019-12-10 17:29:53
问题 I have a ruby on rails web server that I am trying to deploy in production. I am having trouble getting the assets to load in production: .css, .js, and images (seems to work fine in development, due to ). Here is my production.rb Rails.application.configure do # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to

sprockets sass partial erb extension

被刻印的时光 ゝ 提交于 2019-12-10 16:21:46
问题 I have noticed that with the latest rails and sprockets versions (3.2.1 & 2.2.0) there seems to be a problem when the erb file extension is added to a sass partial. e.g. if somestylefilename.css.sass is renamed to somestylefilename.css.sass.erb and the file contains a declaration of a sass variable that uses erb, vis:- $background-colour: <%= '#fff' %>; all is ok. However if a sass partial is renamed from say _sharedpartial.css.sass to _sharedpartial.css.sass.erb then the same variable

how can i insert a variable in to a href value in a link in rails?

房东的猫 提交于 2019-12-10 15:21:16
问题 i have: <a href="/patients/#{@appointment.patient.id}"> <%=h @appointment.patient.f_name %> <%=h @appointment.patient.l_name%> </a> but it dose not work due to a syntax error, if i click on the href it goes to http://0.0.0.0:3000/patients/#{@appointment.patient.id} thanks 回答1: You can do: <a href="/patients/<%= @appointment.patient.id %>"> But it's generally easier to use link_to : link_to(@appointment.patient.f_name + " " + @appointment.patient.l_name, :controller => 'patients', :action =>

Ruby on Rails: Generate HTML for each file in a folder

徘徊边缘 提交于 2019-12-10 11:53:59
问题 I currently have a folder with a list of small *.ogg files that I would like to insert into an html.erb page in my /public folder. The code is within video tags - I want to use Ruby to scan the folder and produce a video snippet for each video it finds in the folder. The code will stay the same between videos, except for the video filename. The resulting page will be a list of playable videos. Any advice would be awesome. 回答1: # assumes the current dir contains the ogg files html = '' Dir

Creating a table in HTML with Ruby?

六眼飞鱼酱① 提交于 2019-12-10 11:33:16
问题 I am trying to make a table with ten values across on each row starting at 1 and going to 100. My Ruby code looks like this: <table border="1"> <% (1..100).each do |i| d3 = (i % 3 == 0) d5 = (i % 5 == 0) i = "<b>#{i}</b>" if d5 i = "<i>#{i}</i>" if d3 %> <tr> <td><%= i %></td> </tr> <% end %> </table> How would I put this in an HTML table in a 10 X 10? 回答1: <table border="1"> <% (1..100).each do |i| d3 = (i % 3 == 0) d5 = (i % 5 == 0) s = "#{i}" s = "<b>#{i}</b>" if d5 s = "<i>#{i}</i>" if d3

Generate HTML files with ERB?

。_饼干妹妹 提交于 2019-12-10 10:11:58
问题 If I have an .html.erb file that looks like this: <html> <head> <title>Test</title> </head> <body> <%= @name %> </body> </html> How can I generate an HTML file that looks like this? <html> <head> <title>Test</title> </head> <body> John </body> </html> How can I execute the template (passing the name parameter) given that the format is .html.erb and be able to get just an .html file? 回答1: #page.html.erb <html> <head> <title>Test</title> </head> <body> <%= @name %> </body> </html> ... require

How to add a link_to in a select_tag with Rails/ERB?

烂漫一生 提交于 2019-12-10 03:19:03
问题 I have the following code in my index.html.erb <%= select_tag 'team_id', options_for_select(@teams.map{|team| ["#{team.name} # {team.nick}", team.id] }) %> Where would I add a link_to helper within that block? Can I even add a link_to for select_tag? The desired link_to would go to '/Teamleader/ID_OF_OPTION_PICKED' UPDATE: To be more clear; when a user selects an option from the select tag, I want to redirect the page to the desired link (from link_to). 回答1: <%= select_tag 'team_id', options