actionview

Render public html for dynamic banners in Rails ?

Hi, I would like to render specific HTML snippets for displaying banners, because each banner has a different nature (some images, some flash, etc). Every banner file is under app/public/banners/. I tried many ways, like: render :file => "/banners/somebanner.html" But it can't locate the file, because Rails looks under app/views. Any ...

Rails ApplicationHelper Escaping HTML without return statement

When I write module ApplicationHelper def flash_helper flash.each do |key, msg| content_tag :div, msg, :class => key ## "<div class=\"key\">" + msg + "</div>" end end end I do not get anything unless I return the statement. The HTML is escaped in my view when I call <%= flash_helper %>. What gives? How can ...

Rails: link_to with block and GET params?

How can I achieve query string and URL parameters in a link_to block declaration? Right now, I have this, which works: <%= link_to 'Edit', :edit, :type => 'book', :id => book %> The above works, and outputs: http://localhost:3000/books/edit/1?type=book What I want to do is something like this: <% link_to :edit, :type => 'book', :i...

How can I get rails to not render escaped quotes as \&quot;

In my layout I have <% @current_user.popups.each do |p| %> <% content_for :script do %> <%= "$(document).ready ( function() { $.jGrowl(\"#{p.message}\", { sticky: true }) });" %> <% end %> <% end %> And then in the script section I have <%= yield :script %> The problem is that this renders the escaped quotes as \&quot; and ...

How to render HTML from a Rails instance variable?

I have an intstance variable I am passing to a view, @body. @body is a string with html in it. <%= @body %> renders the string, not the html. How do I render the html in the string? Possible? Thanks in advance! ...

An alternative to useing datetime_select in Rails

I'm not such a fan of using datetime_select. I think it renders ugly and isn't easy to deal with on post back. How do most people deal with it? Wouldn't it be easier to use a plain textbox and use javascript to validate the input as a date? I will be persisting it as a DateTime value. ...

Setting up actions for the ActionController in Rails

I just issued a [ script/generate scaffold User ] command to generate my files. All the CRUD pages work well so that's good and now I'm trying to create more pages. I create a method in the user_controller.rb file as follows: def login #blahblah end Then created app/views/users/login.html.erb for the view. When I tried accessing it t...

Reusing form_for in view for a mailer errors on forgery

I have a form_for in a template new.html.erb where I do the normal save to the DB and then an e-mail on success. I want the mailer to send the same new.html.erb as the body and pass the model so that the form is fully populated. I'm getting the following error: undefined method `protect_against_forgery?' for #<#<Class:0x000000049d7110>:...

How to DRY up this conditional collection_select in form partial?

Hi all, I have a form partial that is being called in a content_for :sidebar. This collection_select should have "selected" set if the page calling the partial is a specific package page. Otherwise, it should have a "prompt" to select. How would I DRY this up? I tried an inline ternary on a single collection_select to no avail. <%- if ...

Rails variable loads first time and then is nil!

I am receiving the following error: ActionView::TemplateError (You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.include?) on line #24 of app/views/index/index.html.erb: 21: <% @achievements.each do |achievement| %> 22: <%= achievement.name %> 23: ...

Getting undefined method content_for()

Hi, my mac just broke and I had to migrate to an Ubuntu machine. I am working on an app that is already on production on an Ubuntu machine as well. I cloned this app into my new machine and all the view helpers seems to go missing, btw I am ussing HAML. I ran my specs and I am getting tons of : undefined method url_for for # und...

Would Rails' number_to_human(0) giving an error be a bug?

All of the following works well in rails console (Rails 3) except for 0... wouldn't the human readable form of 0 just be 0? irb(main):015:0> helper.number_to_human 1 => "1" irb(main):016:0> helper.number_to_human 2 => "2" irb(main):017:0> helper.number_to_human 200 => "200" irb(main):018:0> helper.number_to_human 3000 => "3 Thousand" ir...

In Rails 3's "rails runner", how do you use number_to_human_size() method?

In a rails console, it can be done this way: ree-1.8.7-2010.02 > helper.number_to_human_size 1 => "1 Byte" ree-1.8.7-2010.02 > helper.number_to_human_size 100000 => "97.7 KB" ree-1.8.7-2010.02 > helper.number_to_human_size 0 => "0 Bytes" ree-1.8.7-2010.02 > helper.number_to_human_size 100000000 => "95.4 MB" but what about in a...

What is the most Rails'ish way of handling multiple layouts/views for the same controller action?

The scenario is this: I have some users on my site. A user has a role, the relevant ones here is admin and normal. I also have a model, let's call it SomeModel. I have created a backend for the site, which uses an admin layout. All admins have full access to edit any content. The problem arises with this relation: User -> owns -> Some...

How to write a view helper that renders works with HAML and ERB?

Hi I am working on a gem that defines a few view helpers and it heavily relies on concat and capture methods but I've recently discovered it doesn't work with HAML (haven't tested thoroughly, but so far doesn't render concat(nated) stuff). I read somewhere there was a haml_concat version of concat. So If I just need to change my concat ...

How to mixin and call link_to from controller in Rails?

This seems like a noob question, but the simple answer is eluding me. I need to call link_to in an ActionController method to spit out an HTML link. ActionView::Helpers::UrlHelper.link_to calls url_for, but this calls the AV module's version instead of the controller's. I managed to coerce this into doing what I intended by putting #...

Rails: variable access: from ApplicationController to ActionView

How do I access in an ActionView a variable, that has been defined in the ApplicationController? In my case, I'd like to make my layout respond to a variable that's been set-up in the ApplicationController. If it were a view, associated with a controller's action, I'd only need to set-up an instance var in the corresponding action and ...

Rails distance_of_time_in_words returns "en, about_x_hours"

I'm having a weird problem, hoping someone knows what the issue is... Using distance_of_time_in_words (and consequently time_ago_in_words) is not returning the actual time distance. Instead it is returning things like "en, about_x_hours" or "en, x_minutes". The pattern is correct, as in: time_ago_in_words(50.minutes.ago) => "en, about...

ACTION_VIEW for images but only a subset of images

I have an app that have more than one gallery. It is a travel app and it have a separate gallery for each trip. When I'm taking pictures with the camera I'm saving them in the default MediaStore of the system. To view an Image I'm using new Intent(Intent.ACTION_VIEW) and it launches the default image viewer. When scrolling with the left...

Generating unique HTML ids in Rails when using a repeated partial that has form_for

I have a view on my current project which does something like the following(in haml): [email protected] do |horse| = render :partial => 'main/votingbox', :locals => {:horse => horse} The in the _votingbox.html.haml file I have the following: %div.votingbox %span.name= horse.name %div.genders - if horse.male %img{:src => '...