我正在尝试从他的个人资料(user_path)中获取用户可以注册他的车辆(new_user_car_path)。但我收到了这个错误:
Routing Error
No route matches {:action=>"new", :controller=>"cars"}
为此我有下一个 routes.rb
Estaciones::Application.routes.draw do
root :to => "static_pages#home"
match '/contact', :to=>'static_pages#contact'
match '/about', :to=>'static_pages#about'
devise_for :users
resources :users do
resources :cars, :only => [:new, :create, :edit, :destroy]
end
这是 user_path 的一部分
<div class="container">
<fieldset>
<h1><%= @user.email %></h1>
<br>
<h2>options</h2>
<p>
<strong>new car registration</strong>
<%= link_to "Sign up now!", new_user_car_path, :class => "btn btn-primary" %>
</p>
<p>
<strong>all cars view</strong>
</p>
</fieldset>
</div> <!-- /container -->
和我的 CarsController
class CarsController < ApplicationController
def new
@car = Car.new
end
def create
@car = current_user.cars.build(params[:car])
if @car.save
redirect_to current_user, :flash => { :success => "car created!" }
else
redirect_to new_user_car_path, :flash => { :success => "sorry try again" }
end
end
end