我只是从我的应用程序中收到此错误,但我不知道为什么会这样。此外,我的应用程序转到了一个未指定的路线(抱歉,如果它有很多代码)。这是我的routes.rb
:
Estaciones::Application.routes.draw do
devise_for :users
root :to => "user#index"
resources :user do
resources :car
end
get "user/new"
post "user/create"
get "user/:id" => "User#show"
end
这是我的用户控制器(我没有问题,仅供参考):
Class UserController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @car.save
redirect_to :action => :show, :id => @user.id
else
redirect_to new_user_path
end
end
def show
@user = User.find(params[:id])
end
end
...我的汽车控制器:
class CarController < ApplicationController
def new
@car = Car.new
end
def create
@user = User.find(params[:user_id])
@car = @user.car.create(params[:car])
if @car.save
redirect_to :action => :show, :id => @user.id
else
redirect_to user_path(@user)
end
end
end
这是我的一部分html.erb
:
<h2>new car registration</h2>
<%= form_for([@user, @user.car.build]) do |f| %>
<p>
<%= f.label :brand %><br />
<%= f.text_field :brand %>
</p>
<p>
<%= f.label :color %><br />
<%= f.text_field :color %>
</p>
<p>
<%= f.label :model %><br />
<%= f.text_field :model %>
</p>
<p>
<%= f.label :year %><br />
<%= f.text_field :year %>
</p>
<p>
<%= f.submit "Create new car"%>
</p>
我的索引只是一个测试,但它有这个
<h1>WELCOME TO TANKING CONTROL ONLINE</h1>
<p>
<strong>for new users </strong>
<%= link_to 'sign up', :action => :new %>
</p>
和用户注册的形式这个
<%= form_for :user, :url => { :action => :create } do |f| %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :email %>
<%= f.text_field :email %>
</p>
<p>
<%= f.label :password %>
<%= f.password_field :password %>
</p>
<p>
<%= f.submit %>
</p>
<br>
<%= link_to '<<Back', :action => :index %>
<% end %>