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
...
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...
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?
...
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...
Is it possible to store erb templates in database? How?
...
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.
...
Hi,
<%= image_tag this.profile.expiring_url(180) %>
keeps giving me grief when profile is nil... what can i do?
Thanks in advance!
...
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...
What is the best way to add comments in erb files, if we do not want them to be generated into the html content?
...
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...
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...
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 ...
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 %> ...
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?
...
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...
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?
...
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...
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...
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...
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...