actionview

Why is link_to not taking me where I want it to?

Hi, I have a model 'Asset' and, on the show page, I have this: <%= link_to_remote 'test', :url => { :controller 'looks', :action => 'whatever' } %> The 'looks' controller and 'whatever' action both exist. Now when I go the the show page for the second Asset and click the test link I get this error: Processing AssetsController#2 (...

Why isn't link_to filling the params correctly?

I'm generating links from the home page (controller = 'landings') via a partial containing: <%= link_to t.to_s, assets_path, :name => t.to_s %> where assets/index is the controller/method that I'd like to pass the :name to. However, after I've clicked the link, and control is thrown to the assets/index controller, params.to_s = "actio...

Rendering a Rails view to string for email

I'd like to send emails from a table every night at midnight, so I've created a model to track all communications to be sent. This Communication model stores who the letter is to, from, and the contents of the letter to be sent as html. The user enters a criteria to match for whom the letter is intended: state, country, favorite color,...

Can the ActionView form input methods create <input> tags with inner html?

I am generating an input like this: <%= form.radio_button("ans", ans.num.to_s) %> The generated html is: <input id="myform_ans_1" name="myform[ans]" type="radio" value="1" /> But what I am looking for is this html: <input id="myform_ans_1" name="myform[ans]" type="radio" value="1">Some Text</input> Is there an option that I can ...

Avoiding repetitive "content_for" in views

I have a submenu placed in my layout wich differs from controller to controller, but not between each controllers method views. What I am currently doing is the following: <% content_for( :submenu ) do %> <%= render :partial => 'submenus/correct_submenu' %> <% end %> In every view for a method My applications layout then has this...

Ruby on rails nested form model

Hi all, I'm trying to use rails nested form_for helper, but I am getting the following error: BlogPage(#49859550) expected, got Array(#31117360) Here are my model objects: class Blog < ActiveRecord::Base # Table Configuration set_table_name "blog" # Model Configuration belongs_to :item has_many :blog_pages accepts_nested_att...

How to call 'time_ago_in_words' from a FunctionalTest?

I'm using 'time_ago_in_words' function in a view, and I need to test the output in the FunctionalTest. But the test can not see 'time_ago_in_words' helper function. What should I do in order to use these helper methods from FunctionalTests? ...

Using Rails form helpers on non-existent methods

Normally, when using form helpers in Rails, each field directly correlates to a method on the appropriate object. However, I have a form (user signup) that needs to include fields that are not part of the user model itself (for instance, card details) but need to appear. How can I build the form so that I can get the necessary fields, ...

How to make iframe pop-up in dialog?

<%= button_to_function("Complete an Offer", "ABA.dialogs.offer(#{???}, {title: 'Complete an Offer'});", :title => "Complete an Offer") %> When a user clicks the button, I want an iframe* to pop-up in a separate dialog box. Any pointers? * ...

Ruby on Rails 3 Beta: On ajax get request, I can't respond back with the html.erb view. Is there a work-around?

I have began playing with Rails 3 beta and I am trying to do my usual starter project. I create a simple list of projects, but use ajax requests for the app's navigation. In Rails 3, my usual code does not work for the basic scaffold, I receive an ActionView:MissingTemplate (Missing template projects/new with {:format=>[:js]} Here is...

Loading association data from database into edit.html.erb

I have the following one to many associations. Document has many Sections and Section has many Items. class Document < ActiveRecord::Base has_many :document_sections, :dependent => :destroy, :autosave => true has_many :document_items, :through => :document_sections end class DocumentSection < ActiveRecord::Base belongs_to :docume...

Ruby Actions: How to avoid a bunch of returns to halt execution?

How can I DRY the code below? Do I have to setup a bunch of ELSEs ? I usually find the "if this is met, stop", "if this is met, stop", rather than a bunch of nested ifs. I discovered that redirect_to and render don't stop the action execution... def payment_confirmed confirm_payment do |confirmation| @purchase = Purchase....

Multiple forms on a single page

I've got an app that's in invite-only beta right now. Problem is, I can't get the invite system to work. :( On my root page there's a login form (which works just fine), and I'm trying to add a "request invite" form on the same page. I started doing it by putting the form for InviteRequest (ActiveRecord) inside a partial, in the "views"...

What is the proper way to specify a path to 'app' in a Rails plugin?

This question came about because the cells gem specifies template directories using File.join('app','cells'). That works fine until you run Rails as a daemon (scripts/server -d). The daemon switches directories to / which leaves the cells template paths pointing to the wrong absolute path. My solution was to set the default paths to Fil...

Trying to extend ActionView::Helpers::FormBuilder

Hello I am trying to DRY up some code by moving some logic into the FormBuilder. After reading the documentation about how to select and alternative form builder the logical solution for me seemed to be something like this. In the view <% form_for @event, :builder => TestFormBuilder do |f| %> <%= f.test %> <%= f.submit 'Updat...

Class name to view path

Hi, I have a RoR application and model SomeModel. I have views for this model and I want to know - is there any method to get the view's path? Of course I can use for this model instance m = SomeModel.new v = m.class.class_name.pluralize.downcase It's working, but maybe you know a better way? :) ...

Rails: Should partials be aware of instance variables?

Ryan Bates' nifty_scaffolding, for example, does this edit.html.erb <%= render :partial => 'form' %> new.html.erb <%= render :partial => 'form' %> _form.html.erb <%= form_for @some_object_defined_in_action %> That hidden state makes me feel uncomfortable, so I usually like to do this edit.html.erb <%= render :partial => 'form...

How can I change Rails view code for site visitors using SSL?

My Rails app has some pages which are SSL-required and others which are SSL-optional. The optional pages use some assets which are served off-site (images from a vendor) which have both http and https URLs. I need to use https when the page is accessed via SSL to avoid the dreaded "this page contains both secure and insecure elements" wa...

rails date field format on error

Hi, I have an input field that captures a date in my form <%= f.text_field :from_date, :style => 'width:80px;' %> The user enters the date in the following format MM/DD/YYYY. However, when there is a validation error in the model and the form is displayed back to the user with the entered values, the date format is converted to YYYY-...

How does the yield magic work in ActionView?

I was looking at how content_for works and observed the block.call in the capture_erb_with_buffer method. It apparently magically writes to the buffer variable which is then pruned. However, this I believe is deprecated and you can just call <%=yield :tag%> now. How does this work? If I call yield from an ERB template where does that yie...