在 Michael Hart 的 Ruby on Rails 教程中注册新用户时,我遇到了一个错误。我是 Rails 的新手,但我一直在寻找几个小时,似乎找不到任何东西来解决这个问题。我最初的想法是它特定于以下行:
redirect_to @user
这是我的users_controller.rb文件
#!/bin/env ruby
# encoding: utf-8
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
flash[:success] = "Welcome to the Sample App!"
 redirect_to @user
else
render 'new'
end
end
end
这是我收到的错误消息:
用户控制器中的 NoMethodError#create
用于#Rails.root 的未定义方法`: /Users/mikedeverna/Documents/rails_projects/sample_app
应用程序跟踪 | 框架跟踪 | 完整跟踪 app/controllers/users_controller.rb:18:in `create'
这是我routes.rb
文件中的代码:
SampleApp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'static_pages#home'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
我无法找到正确的路径。干杯