我完全难过 - 看了所有嵌套资源问题但找不到答案。
拥有嵌套资源并尝试使用new_user_path(父资源)获取link_to以显示新用户页面,但rails希望路由到子资源(simple_products_configs)控制器而不是父资源控制器。
有人知道我做错了什么以及如何解决?它可能是view_ file中带有simple_form的东西吗?
错误讯息:
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
用户/ 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>
用户/ _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) %>
路线:
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
答案 0 :(得分:0)
检查用户控制器是否已正确设置并且新控制器操作和其他 REST 控制器操作已正确设置.. < / p>