0
votes

Am totally stumped--have looked at all nested resources questions and cannot find the answer.

Have nested resources and am trying to get a link_to with new_user_path (parent resource) to display new user page but rails wants to route to the child resource (simple_products_configs) controller instead of the parent resource controller.

Would anyone know what I'm doing wrong and how to fix? Could it be something in the view file with simple_form?

Error message:

Routing Error

No route matches {:controller=>"simple_product_configs", :user_id=>#<User id: nil, email: "", encrypted_password: "", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, authentication_token: nil, created_at: nil, updated_at: nil, first_name: nil, last_name: nil, t_and_c: nil, deleted_at: nil, from_social_network: false>}

routes.rb:

resources :users do

  resources :simple_product_configs

end

users/index.html.erb:

<div class="row-fluid">
  <h1>New <%= user_type_name(current_user) %></h1>
</div>
<div class="row-fluid">
  <span class="pull-right required-label">Required Fields <abbr title="required">*</abbr></span>
  <div class="span12">
    <%= simple_form_for(@user, :defaults => {input_html: { :class => 'span4' }}, :html => {:class => 'form-horizontal'}) do |f| %>

      <%= error_messages_helper(@user,"Could not register account") %>

      <%= render('form', f: f) %>

      <div class="control-group">
        <div class="controls">
            <%= f.submit "Create #{user_type_name(current_user)}", :class => 'btn' %>
            <%= link_to 'Cancel', dashboard_path, :class => "btn" %>
        </div>
      </div>
    <% end %>
  </div>
</div>

users/_form.html.erb:

<%= f.input :first_name, :label => "First Name:" %>
<%= f.input :last_name, :label => "Last Name:" %>    
<%= f.input :email, :label => "Email:" %>        
<%= link_to 'Product Configs', user_simple_product_configs_path(f.object) %>

routes:

    user_simple_product_configs GET    /users/:user_id/simple_product_configs(.:format)          simple_product_configs#index
                                POST   /users/:user_id/simple_product_configs(.:format)          simple_product_configs#create  
 new_user_simple_product_config GET    /users/:user_id/simple_product_configs/new(.:format)      simple_product_configs#new
edit_user_simple_product_config GET    /users/:user_id/simple_product_configs/:id/edit(.:format) simple_product_configs#edit
     user_simple_product_config GET    /users/:user_id/simple_product_configs/:id(.:format)      simple_product_configs#show
                                PUT    /users/:user_id/simple_product_configs/:id(.:format)      simple_product_configs#update
                                DELETE /users/:user_id/simple_product_configs/:id(.:format)      simple_product_configs#destroy
                          users GET    /users(.:format)                                          users#index
                                POST   /users(.:format)                                          users#create
                       new_user GET    /users/new(.:format)                                      users#new
                      edit_user GET    /users/:id/edit(.:format)                                 users#edit
                           user GET    /users/:id(.:format)                                      users#show
                                PUT    /users/:id(.:format)                                      users#update
                                DELETE /users/:id(.:format)                                      users#destroy
1

1 Answers

0
votes

Check that the Users controller is properly set-up and that new controller action and other REST controller actions are properly set..