Are variables defined locally in a partial also visible to the invoking erb template?
If I declare local variables in a partial and then render the partial from another erb template, will the latter also have accces to those local variables? ...
If I declare local variables in a partial and then render the partial from another erb template, will the latter also have accces to those local variables? ...
A first look I thought erb accepts any Ruby code, but I've got this strange behaviour... I have an array [of tags for my article], and I want to make a nice display for them. So I'm writing something like this: <ul> <% @post.tags.each do |item| %> <li>item</li> <% end %> </ul> The wrong output looks like this: <ul> <li>...
I am getting started with HAML and am working on my converting my first file. The ostensibly correct omission of the "- end": - if current_user = link_to 'Edit Profile', edit_user_path(current_user.id) = link_to 'Logout', logout_path - else = link_to 'Register', new_user_path = link_to 'Login', login_path gets me: app/views/layouts/a...
Hey, I'm new to Rails and Ruby in general. I was wondering if it's possible to use an embedded ruby css file (css.erb), similar to using html.erb files for views. For example, I'm using <%= stylesheet_link_tag "main" %> to link to my main.css file in public/stylesheets, but when I change the file extension from main.css to main.css.e...
Hello! I have an ERB template inlined into Ruby code: require 'erb' DATA = { :a => "HELLO", :b => "WORLD", } template = ERB.new <<-EOF current key is: <%= current %> current value is: <%= DATA[current] %> EOF DATA.keys.each do |current| result = template.result outputFile = File.new(current.to_s,File::CREAT|File::TRUNC|File::R...
Currently, when I get an error on an erb template (for use with HTTPServer/cgi) I do the following: If it's a small change, revert, save and retest. For a large change or new file, delete or comment 1/2 the code, and retest. Perform a binary search until I've deleted/found the broken code. The call stack doesn't seem to correspond t...
I want to print out some debug messages in my erb template when it is called in development mode, but not when it is called in production mode (i.e.) <%= debug variable_name %> However, this will be printed in any mode. I found I can do <% if logger.debug? debug variable_name end %> which seems to work. Is this the proper...
I am teaching myself rails (coming from PHP for web apps) and I can't find any good docs to help me. But I was wondering how would you tell your method to take the last post(controller is post) in the database? I tried Post.find(:last) but that did nothing sadly. Anyone know? ...
I expected to see the word "test" appear in the output once and the word "hello" appear once. But I'm puzzling over the fact that if I do this, the word "test" is displayed twice. <div> <h3>test</h3> </div> <% def helo %> <% "hello" %> <% end %> <%= helo %> I assume there's a simple explanation for this related to some quirk o...
Hi, I am aware of quite a few different JavaScript based online text editors for WYSISYG html editing, however I am trying to find something similar for ERB Ruby templates. Essentially it would be just like the other editors, however it would not garble or encode the <%= foo.to_s %> type code blocks. Is there anything out there which w...
I have a to-do list with 5 tasks that are stored on the same record. Todo.task_one, Todo.task_two, etc. What I would like to do is be able to loop through the fields like this total_tasks = ["one", "two", "three", "four", "five"] for tasks in total_tasks Todo.task_#{tasks} = "text here" end However, this doesn't work unless I use e...
Hi For some reason html escaping isn't working in my Rails application. Even if I write something like <%=h '©äö' %> it isn't converting any of the characters to HTML entities. I have no clue what the could be. It worked always fine and now just suddenly it don't. Any ideas? ...
I just installed Netbeans 6.7 for Ruby and one of the things that bugs me is I have to type both the opening and closing HTML tags even though it seems to recognize that I have completed the opening tag. Is it possible to configure it to automatically type the closing HTML tag for you, as some other IDEs do? ...
I have a method on an active record class that renders an ERB template for a messaging system. The simplified code looks like this: ERB.new(template).result(binding) where binding is the current Binding of the ActiveRecord model object and template is an erb template file read in from the file system. I would like to use some named...
I could use some help on including and extending Ruby modules and classes. My previous question handled the named routes, but not all of the view/tag helpers due to the default_url_options Hash. The issue here is that ActionController::UrlWriter methods, like url_for, call the class attribute default_url_options. So when including Act...
Hi. I just installed HTML Tidy plugin for eclipse. I added the html.erb file type and now it will do its magic on my erb files. However it puts in the title tag and changes a lot of my characters to escape characters. How can I stop this from happening - or is there a ruby alternative which will go through my code, reindent, and stick in...
I find myself frequently writing code like this in the HTML HEAD and other places: <% if @canonical_url %> <link rel="canonical" href="<%= @canonical_url %>"/> <% end %> I then set the variable in the controller if it's appropriate. Is there any way of writing the equivalent on one line, or maybe a different way of organizing the c...
I right clicked the project file for my rails project and created a new ruby file. Then i right clicked views and created a new erb file I added a textbox and submit button and click on page (design) and it gives me this error: failed to locate layout file can anyone help me pleasE? thnx ...
Sometimes it's more convenient to print in <%%>. How to do it in Rails? ...
When your application has a view that is only accessible after submitting another form (think signup screen, a shopping cart checkout, or a wizard-like interface), what's the best way to work on the successive views without having to click through all the preceding steps? Let's say we're working on the second or third step of a build-a-...