14
Ruby on Railsの新機能で、MVCの仕組みを強く理解しようとしています。このリクエストフォーマットとバリアントのテンプレートがありません
私は次のようでした:次のように私は、メソッドを作成し、私のバブルコントローラで
rails new bubblesman
rails generate controller bubble
:
def available
puts "YEP!!!!!!"
end
私は私のroutesファイルに次のように置く:
'welcome' => 'bubble#available'
http://localhost:3000/welcome 次のエラーが表示されます。
ActionController::UnknownFormat (BubbleController#available is missing a template for this request format and variant.
request.formats: ["text/html"]
request.variant: []
NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not… nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.):
私はこれを私のメインコントローラの代わりにヘルパーコントローラに入れれば、すべて正常に動作します。
作品。ありがとうございました。私のコントローラで複数のメソッドを使用したいのであれば、毎回新しいhtml.erbが必要ですか? – codingdraculasbrain
私はその仕事をするために思うことができる唯一の方法は、すべてのコントローラメソッドの最後にリダイレクトを使用して、表示するための 'available'メソッドを指すことです。 しかし、基本レベルでは、たいていの場合、ほとんどの方法でhtml.erbが必要です。 – Avir94
ありがとうございます。これは実際にトンに役立ちます。私は多くのチュートリアルを読んだことがありますが、今までこの部分を実際には把握していませんでした。 – codingdraculasbrain