2012-07-19 2 views
0

내 응용 프로그램에서이 오류가 발생하지만 그 이유는 알 수 없습니다. 또한, 내 응용 프로그램은 지정되지 않은 경로로 이동합니다 (코드가 많은 경우 미안합니다). (여기에 내가없는 문제가 단지 참고 용입니다) 여기 알 수없는 동작 CarController에 대한 'index'동작을 찾을 수 없습니다.

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 

내 사용자 컨트롤러 : 이것은 내 routes.rb입니다

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> 

및 사용자 등록의 형태를 가지고 그것을 당신은 당신의 CarController에 액션 '인덱스'를 누락이

<%= 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 %> 
+0

색인 템플릿은 어디에 있습니까? – Zabba

+0

devise_for : 사용자가 생성되는 사용자를 처리하므로 맨 아래에 사용자 경로가 필요 없습니다. –

+0

나는 왜 내가 때때로이 오류가 발생하는지 모르겠다. [POST] "/ users/1/cars"와 일치하는 경로가 없음 – BlackSan

답변

2

..

def index 
end 

'cars'보기에 'index.html.erb'가 있는지 확인하십시오.

[업데이트] 당신의 노선

resources :users do 
    resources :cars 
end 

공지 사항 사용자와 자동차의 복수해야한다.

+0

나는 그랬지만 지금은 새로운 오류가 발생한다. 새로운 게시물? – BlackSan

+0

무엇이 오류입니까? –

+0

@BlackSan 응답이 게시물 문제로 업데이트되었습니다. –

관련 문제