Is there a neater syntax for displaying a variable in erb?
I'm new to Ruby, and I found the <%= @my_variable %> a little lengthy and less readable. Shouldn't erb have something like ${@my_variable} (like the good old Velocity engine in Java)? ...
I'm new to Ruby, and I found the <%= @my_variable %> a little lengthy and less readable. Shouldn't erb have something like ${@my_variable} (like the good old Velocity engine in Java)? ...
Right now I'm building a project management app in rails, here is some background info: Right now i have 2 models, one is User and the other one is Client. Clients and Users have a one-to-one relationship (client -> has_one and user -> belongs_to which means that the foreign key it's in the users table) So what I'm trying to do it's on...
Sorry for the semi-generic title, but I'm still pretty new at rails and couldn't think of a succinct way to put the question. I have a basic habtm model setup: a Project has many Resources and a Resource can have many Projects. I have the database and models setup properly, and can do everything I need to via the console, but I'm having...
So, I have <script type="text/javascript"> function grabFocus(){ document.getElementByID("category_name").focus(); } </script> <div> <h1>New category</h1> <br/> <% remote_form_for :category, @category, :url=>{:action=>'ajax_create'} do |f| %> <%= f.error_messages %> <%= f.hidden_field :object_type %> <p> <%= f.text_field...
I'm a bit of a Ruby on Rails amateur, and I am trying to nest a div tag inside of an anchor tag in rails. I can make it work, but the resulting code I have written is terrible and is certainly NOT the rails way. Here is an example of what I am trying to accomplish in HTML: <a href="tell-a-friend"> <div id="tellafriend"> <strong>Str...
I'm working with a that allows the user to add new contents to a shipment box. For example: The user is setting up a shipment, each shipment can include multiple boxes, and each box can contain multiple contents. So I have link_to_remote connected like: In my shipment box partial: <div class="shipping_box" id="shipping_box"> #so...
Hey, I'm using Ruby on Rails and need to run a block of Ruby code in one of my html.erb files. Do I do it like this: <% def name %> <% name = username %> <%= name %> or like this: <% def name name = username %> <%= name %> Thanks for reading. ...
We have a user model which :has_one detail. In a form_for a user, I want a drop-down to select the user's details' time_zone. I've tried <% form_for @user do |f| %> ... user stuff ... <%= f.select :"detail.time_zone", ...other args... %> <% end %> but I get a NoMethodError for detail.time_zone. What's the correct syntax fo...
I do dump the value of RUBY_VERSION => 1.8.7 every time, the value of [1,3,5].shuffle is also [1,3,5] i have to add a srand(Time.now.to_i) or srand() in front of it to make it random... I thought srand is automatically called? but maybe not in a .cgi environment? if i use irb, and look at [1,3,5].shuffle, and exit, and re-enter irb, e...
How do you comment out html mixed with ruby code? some text <% ... %> more text <%= ... %> something else <% ... %> In jsp it's real simple: <%-- ... --%>, but I'm unable to find any concise option in rails. Simple html comments <!-- ... --> do not work: ruby code is still executed and yells errors. There's an option to use if fal...
I have a Rails application running on Rails 2.3.9. It runs fine with ruby 1.8.7. I'm testing it with ruby 1.9.2-head right now. The application loads fine until I try to load a page that relies on a unicode string. Then I get the infamous encoding error: ActionView::TemplateError (incompatible character encodings: UTF-8 and ASCII-8BIT...
I'm trying to migrate a sinatra application to ruby 1.9 I'm using sinatra 1.0, rack 1.2.0 and erb templates when I start sinatra it works but when I request the web page from the browser I get this error: Encoding::CompatibilityError at / incompatible character encodings: ASCII-8BIT and UTF-8 all .rb files has this header: #!/usr/b...
We are currently in the process of upgrading our rails version and I have come across some weird error in one of my date_select tags. Here is the culprit: <%= date_select :consultant_assignment, :start_date, :order => [:day, :month, :year], :start_year => 5.years.ago.year, :end_year => 5.years.from_now.year, :use_short_month => t...
EDIT: forgot to include my environment info... Win7x64, RubyInstaller Ruby v1.9.1-p378 EDIT 2: just updated to v1.9.1, patch 429, and still getting this same error. Edit 3: running this same code in Ruby v1.8.7, patch 249, works fine. so it's v1.9.1 that broke it, apparently. I'm new to using ERB and the samples i could find are... um...
I am using ERB via console for metaprogramming (for math software). For example, I have file test.erb containing text line before ruby <%= 'via <%=' %> <% print 'print' %> <% puts 'puts' %> text line after ruby When I parse it by $ erb test.erb, I get the following output printputs text line before ruby via <%= text line af...
I am attempting to pass 2 classes to an element in a rails 3 application and having some issues with encoding. <td class="edit"> <%= link_to 'Edit', edit_link_url(link, :class => 'edit_link ui') %><br /> <%= link_to 'Delete', link_url(link, :class =>'delete_link ui'), :confirm => 'Are you sure?', :method => :delete %> </td> c...
I am using Puppet for automating configuration management across hosts. It can use erb templates to set up configuration files of various services like apache, postfix etc. across different hosts Till now we were using shell scripts full of sed, awk, grep filters and such, and now I need to port that code to ruby erb templates. Let's...
Do asp.net aspx views have tags that that work similar to the Ruby erb <% -%> ? I don't like all these line breaks in my asp.net mvc generated html. As for the other view engines (nhaml, spark, razor) I don't want to use them yet. Quick example of the difference between <% %> and <% -%> in erb: 1. <% %> <% 3.times do %> Ho!<br /> <% e...
I am using ERB for metaprogramming of some math language. If I could extend ERB functionality to handle %= tags, it would allow me to simplify my sources significantly. I simply want to get output of the line in analogy with <%= %>. I have tried to dig into /usr/lib/ruby/1.9.1/erb.rb file, but got lost very quickly. May be you can help w...
Hi, I'm using a pre-commit hook for Git that checks the syntax of my files before I can commit them. In a Rails 3 app (I'm using the new form helper's syntax : <%= form_for @article do |f| %> but I get a syntax error, not when I use the app, but when I check for the syntax through the ruby CLI command or the Textmate's bundle command. ...