2017-09-05 6 views
0

私はRailsの新機能ですので、私ができる限りこれを試して説明します。私は単純なProductsモデルを持っていて、フィールドの1つはストライプ・プラン名の名前です。これは新製品の追加が可能なため、選択すると計画の名前がパスの最後に追加されます。それはテストのためにコード化された素晴らしいハード作品です。Rails 5.0のキー値パスを文字列として出力する

Heres my products/show.html.erb質問があります。経験豊富なRails開発者がこの問題を見るはずです。

製品/ show.html.erb私は

... 
<%= link_to 'Subscribe', new_subscription_path(plan: '<%= @product.stripe_name %>'), class: 'btn btn-primary' %> 
... 

は<% = @ product.stripe_name%を持つ必要があるものハードコーディングされた

... 
<%= link_to 'Subscribe', new_subscription_path(plan: 'monthly'), class: 'btn btn-primary' %> 
... 

製品/ show.html.erb > inは文字列としてエラーをスローします。

は、望ましい結果が

http://127.0.0.1:3000/subscription/new?plan=monthly 

答えて

3

ブラウザで次のようになりますこの:

<%= link_to 'Subscribe', new_subscription_path(plan: '<%= @product.stripe_name %>'), class: 'btn btn-primary' %> 

は、このことが必要です。

<%= link_to 'Subscribe', new_subscription_path(plan: @product.stripe_name), class: 'btn btn-primary' %> 

あなたは内部<%= ... %>を入れていません別の<%= ... %>

+0

ストライプではプラン名@ product.stripe_nameが文字列であることが期待されるため、これは機能しません。 –

+0

私は試してみましたが、ブラウザー 'http://127.0.0.1:3000/subscription/new'に新しいパスを出力しました –

+1

ルーキー見落とし...許可されたファイルとして':stripe_plan'をproducts_controller。 –

関連する問題