私は非常に単純なレールアプリを持っています。Card の足場を生成しました。これにより、ID http://app.com/cards/3を使用して特定のルートに移動して記録することができます。
ルートhttp://app.comに移動すると、ランダムな ID を持つランダムなカードを表示するようにルーティングされ、「X」と表示されます ( http://app.com/cards/X )
これは間違っていると確信していますが、Cards Controller に以下を追加しようとしました:
def random
@card = Card.order("RANDOM()").first
end
そして、routes.rb に追加します:
root :to => 'cards#random'
ルートに移動しようとするとブラウザに表示されるエラー:
Template is missing
Missing template cards/random, application/random with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "/Users/patricia/Documents/Repos/coastguard-quiz-rails/app/views"
最後に、「rake routes」を実行すると、次のようになります。
cards GET /cards(.:format) cards#index
POST /cards(.:format) cards#create
new_card GET /cards/new(.:format) cards#new
edit_card GET /cards/:id/edit(.:format) cards#edit
card GET /cards/:id(.:format) cards#show
PUT /cards/:id(.:format) cards#update
DELETE /cards/:id(.:format) cards#destroy
root / cards#random
誰かが私を正しい方向に導いてくれませんか? 前もって感謝します。