Question

In a Rails 3 application, I have a "table" partial that contains a data entry form table, plus a separate smaller form (mostly hidden fields) below it to clear the table data. I have a third form underneath the partial to add a new column to the table contained in the partial. The page loads fine. The small form to clear the table data works, and refreshes the partial as it is supposed to. BUT, When I submit the add-new-column form, I get this routing error:

ActionView::Template::Error (No route matches {:controller=>"outcome_results", :action=>"clear_table"}):

    70:                         </table>
    71:                 <%= submit_tag "Save" %>
    72:         <% end %>
    73:                 <%= form_tag url_for(:controller => 'outcome_results', :action => 'clear_table'), :id => "clear_data_table_link", :remote => true do %>
    74:                 <%= hidden_field_tag "subgroup_id", subgroup_id %>
    75:                 <%= hidden_field_tag "outcome_id", @selected_outcome_object.id %>
    76:                 <%= hidden_field_tag "timepoint_id", timepoint_id %>

app/views/outcome_results/_table.html.erb:73:in `_app_views_outcome_results__table_html_erb__204353865_18893424_435027370'
app/controllers/outcome_columns_controller.rb:36:in `block (3 levels) in create'
app/controllers/outcome_columns_controller.rb:35:in `block (2 levels) in create'
app/controllers/outcome_columns_controller.rb:33:in `create'

Line 72 is the end tag of the first (table/data entry) form. Line 73 is the form tag for my clear-table-data form which works fine on its own - no routing errors there.

My routes.rb is crazy long but contains this line:

match 'projects/:project_id/studies/:study_id/clear_table' => 'outcome_results#clear_table'

The add-new-column form looks like this:

<div id="outcome_column_validation_message"></div>
<%= form_for @outcome_column, :action => :create, :remote => true,  :id=>"outcome_columns_form" do |f| %>

<%= hidden_field_tag "outcome_id", !@selected_outcome_object.nil? ? @selected_outcome_object.id : nil %>
<%= hidden_field_tag "subgroup_id", !@selected_timepoint.nil? ? @selected_timepoint : 0 %>
<%= hidden_field_tag "timepoint_id", !@selected_subgroup.nil? ? @selected_subgroup : 0 %>
  <div class="field">
    Custom Column Title: <%= f.text_field :name %> Description: <%= f.text_field :description %> <%= f.submit "Add Custom Column" %>
<% end %>

and the format section of the "create" action in the "outcome_column" controller looks like this:

respond_to do |format|
 format.js {
        render :update do |page|
             page.replace_html 'outcome_results_table', :partial => 'outcome_results/table'
             page['outcome_columns_form'].reset
             page.replace_html 'outcome_column_validation_message', ""
        end
     }
end

I can post more code if it would help... anyone have any ideas about this routing error?

Thanks in advance.

Was it helpful?

Solution

The route would take two arguments: a project_id and a study_id. This is not matching the route because you have not passed through these two parameters to the url_for in your form_tag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top