【发布时间】:2014-07-25 21:08:37
【问题描述】:
我正在尝试构建一个应用程序,让用户可以使用安静的路由创建行程,但是,当用户登录并尝试创建行程时,我遇到了问题。 我得到“没有路线匹配 [POST] “/users/8/trips/new””
这些是路线:
resources :users do
resources :trips
end
这是行程控制器:
class TripsController < ApplicationController
def new
@trip = Trip.new
end
def create
@trip = Trip.create(trip_params)
redirect_to root_path
end
end
这是创建新行程的表格。这是我单击提交并收到错误的地方:
<div class="trip_form">
<%= form_for :trip do |f| %>
<%= f.label :where, "Where?" %><br/>
<%= f.text_field :where, placeholder: "Hawaii" %><br>
<%= f.label :when, "When?" %><br/>
<%= f.text_field :when, placeholder: "#" %><br>
<%= f.label :price_per_person, "Price per person? (Approximately)" %><br/>
<%= f.text_field :price_per_person, placeholder: "$550" %><br>
<%= f.submit "Create Trip Idea"%>
<% end %>
这些是路线:
$ rake routes
Prefix Verb URI Pattern Controller#Action
user_trips GET /users/:user_id/trips(.:format) trips#index
POST /users/:user_id/trips(.:format) trips#create
new_user_trip GET /users/:user_id/trips/new(.:format) trips#new
edit_user_trip GET /users/:user_id/trips/:id/edit(.:format) trips#edit
user_trip GET /users/:user_id/trips/:id(.:format) trips#show
PATCH /users/:user_id/trips/:id(.:format) trips#update
PUT /users/:user_id/trips/:id(.:format) trips#update
DELETE /users/:user_id/trips/:id(.:format) trips#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
PATCH /users/:id(.:format) users#update
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
root GET / users#index
我想我应该可以只填写旅行新表格,然后按提交即可 自动与行程控制器中的创建方法通信?当我在表单中将 :trip 更改为 @trip 时,我收到此错误:
Trips 中的 NoMethodError#new
未定义的方法`trips_path'
谢谢!
【问题讨论】:
标签: ruby-on-rails ruby rest controller routing