erb

Is using js.erb files in conjunction with rails and jquery safe?

Hi, I have seen many resources on using jQuery with rails where people recommend having callback functions in .js.erb files, however I have also heard that passing data this way leaves me vulnerable to man in the middle attacks. Is this true? What are the security concerns and is there a way to do it safely? Thanks ...

Erb with Sinatra in ruby

So I have a webserver I've built using sinatra, the meat of which goes like this: set :variable,"value" get '/' do erb :index end And, of course, the template in views/index.erb which looks something like this: <html> <!-- etc --> <ul> <% my_array.each do |thing| %> <%="Something: #{thing}, variable from sinatra: #{settings.v...

What is the meaning of "-" in blocks of server-side code in ruby on rails?

I often see things like this in rails views: <% form_tag some_path do -%> <% end -%> Why is there a "-" at the end of each of those lines? My code works fine without it, but is it a best practice or some kind of security measure? ...

Library to parse ERB files

I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type manner. The files I am attempting to parse contain HTML fragments intermixed with dynamic content generated using ERB (standard rails view files) I am looking for a library that will not only parse the surrounding content, much the way that Hpricot or No...

Rails: storing erb templates in database

Is it possible to store erb templates in database? How? ...

Rails - How can I detect if the content_for content was provided?

Hi - I want to detect if content was provided for content_for tag in my template, and if not fall back to default value: <title> <% if content_is_provided -%> <%= yield :title -%> <% else -%> 404 - Page Unknown <% end -%> </title> Any easy way to detect this? I tried <% if :title -%> but that didn't do much. thanks. ...

Rails handling .Erb with Nils

Hi, <%= image_tag this.profile.expiring_url(180) %> keeps giving me grief when profile is nil... what can i do? Thanks in advance! ...

Ruby w/ Postgres & Sinatra - Query won't order right with parameter??

So I set a variable in my main ruby file that's handling all my post and get requests and then use ERB templates to actually show the pages. I pass the database handler itself into the erb templates, and then run a query in the template to get all (for this example) grants. In my main ruby file: grants_main_order = "id_num" get '/gran...

Best way to add comments in erb

What is the best way to add comments in erb files, if we do not want them to be generated into the html content? ...

Rendering HTML in rails without actually displaying it

Hello all, My current project requires me to assemble a .zip file containing HTML and text-only templates for a user to download, for importing into an email marketing program. I've inherited this project, and currently the code uses a "fake" model (that is a model that does not directly correlate to a database table), in which it stor...

Rendering a variable with erb.

I've got the following problem: I have rhtml (html minced together with ruby inside <% %> and <%= %> tags) stored in a database which I want to render. The information is acquired through a query. I need to be able to evaluate the information I get from the database as though as it was normal content inside the .erb-file. What I currentl...

Restricting Access in ERB code.

I am trying to build a CMS using ERB. Is there a way you can give ERB code read-only access to your models? For instance, I want to be able to load any information on my models (Model.all, Model.find_by_slug, Model.find_by_name, Model.other_model.name, etc...), but I don't want to be able to change this data. Can you disable ERB from ...

Relative path issue within Sinatra view

I am using the following code to check existence of a file before publishing an image in my erb file. This is a ruby/sinatra app - not rails. <% @imagename = @place.name + ".jpg" %> <% if FileTest.exist?( "/Users/Tim/projects/game/public/" + @imagename ) %> <p><img src= '<%= @imagename %>' width="400" height="300" /> </p> <% end %> ...

In Rails, how can I allow some html in a text area?

I have a Rails app (blog) that I am creating. Very basic stuff. In my content area I have a text area for the content of the post. I am needing to include some html in the text area (links, formating, etc). <%= f.text_area :content %> Is there another tag that I can use instead of text_area, that will allow me to do this? ...

On Ruby on Rails, <%= or <% should only matter whether it is show or no show, but why will it give compile error?

The following code: <div id="vote_form"> <%= form_remote_tag :url => story_votes_path(@story) do %> <%= submit_tag 'shove it' %> <% end %> </div> gives compilation error while if the first <%= is replaced with <%, then everything works. I thought they only differ by "show" or "not show", but why will it actually cause a comp...

Possible to embed markdown within erb?

If you use haml as rails view template, you can write portion of your page using markdown by using the ":markdown" filter. Is is possible to do the same using erb? ...

Ruby erb template- try to change layout- get error

Hi there! I'm working my way through adapting a template I have been given that is basically a list of products for sale. I want to change it from a top-down list into a table layout. I want to end up with something as follows- <div id= 'ladiesproducts'> <% ladies_products = hosting_products.find_all do |product| product.name.match("lad...

HAML-like syntax for non-HTML documents?

I love using HAML for HTML documents. It has clean syntax that's much more attractive than ERB. It works perfectly for HTML documents. What about for non-HTML? Such as, for example, an email or text document with certain automatically-substituted components? I've been falling back to ERB, but don't like the heavy syntax compared to HAML...

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

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...

how to use erb to output file after binding

Hi, I got the following example: require 'erb' names = [] names.push( { 'first' => "Jack", 'last' => "Herrington" } ) names.push( { 'first' => "LoriLi", 'last' => "Herrington" } ) names.push( { 'first' => "Megan", 'last' => "Herrington" } ) myname = "John Smith" File.open( ARGV[0] ) { |fh| erb = ERB.new( fh.read ) print erb.result...