新手在學習Hartl's Rails Tutorial & video cast後,在他的第一個rails應用程序上工作。STI路由錯誤
我使用STI模型,其中:
class User < ActiveRecord::Base
class Kid < User
class Parent < User
用戶擁有的基本要素:姓名,電子郵件等
我遇到的問題是路由。我繼續努力確定哪種模型最終在這種情況下效果最好(STI或多態)。我已經開始使用STI,如果能夠確定路由問題,我認爲我可以做到這一點。
我的問題是我的編輯正在尋找在用戶控制器中的「更新」行動時,我希望它的路線kidupdate我一直在閱讀很多關於SO STI路由職位,但我似乎無法圖爲什麼這不會正確路由。
Rspec測試。它配備的錯誤從 「click_button」
describe "with valid information" do
let(:new_first) { "New First" }
let(:new_last) { "New Last" }
let(:new_email) { "[email protected]" }
before do
fill_in "First Name", with: new_first
fill_in "Last Name", with: new_last
fill_in "Email", with: new_email
select "Kid", from: "Are you a Kid or Parent"
fill_in "Password", with: kid.password
fill_in "Confirmation", with: kid.password
click_button "Save changes"
end
Rspec的錯誤:
KidPages edit with valid information
Failure/Error: click_button "Save changes"
AbstractController::ActionNotFound:
The action 'update' could not be found for UsersController
# (eval):2:in `click_button'
# ./spec/requests/kids_pages_spec.rb:32:in `block (4 levels) in <top (required)>'
路線:
root / static_pages#home
help /help(.:format) static_pages#help
contact /contact(.:format) static_pages#contact
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
kidshow /kids/:id(.:format) users#kidshow
kidupate PUT /kids/:id(.:format) users#kidupdate
kidedit /kids/:id/edit(.:format) users#kidedit
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
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
的routes.rb
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/contact', to: 'static_pages#contact'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete
match 'kids/:id', to: 'users#kidshow', :as => 'kidshow'
match 'kids/:id', to: 'users#kidupdate', :via => 'put', :as => 'kidupdate'
match 'kids/:id/edit', to: 'users#kidedit', :as => 'kidedit'
resources :users
resources :sessions, only: [:new, :create, :destroy]
我一直在掙扎與這些概念和這個問題有關的幾個星期我欣賞幫助。
另外,我的兩分錢關於STI和多態性。它們實際上用於各種不同的用例。當您有兩種不同類型的用戶時,您可能會在少數幾列中使用STI。您使用「類型」colomn在UserTypeA模型和UserTypeB模型中分配它們。 [Rails中的多態性(click)](http://railscasts.com/episodes/154-polymorphic-association)是完全不同的。對STI的改進是使用2個配置文件表來存儲其不同的用戶字段,並且主要將用戶表用於認證數據。 – benzhang