「フォローボタン」に「フォロー+ユーザー名」(ユーザー名は各ユーザーのインスタンス変数)を表示したい場合、これを実現するための良い方法は何でしょうか。
<div class="actions"><%= f.submit "Follow, <%= @user.name %>" %></div>
ありがとう!
「フォローボタン」に「フォロー+ユーザー名」(ユーザー名は各ユーザーのインスタンス変数)を表示したい場合、これを実現するための良い方法は何でしょうか。
<div class="actions"><%= f.submit "Follow, <%= @user.name %>" %></div>
ありがとう!
<div class="actions"><%= f.submit "Follow, #{@user.name}" %></div>
これは、Rubyの通常の文字列補間です。I18nを使用する場合は、次のようにすることができます。
<div class="actions"><%= f.submit t(:follow, :name => @user.name) %></div>
そしてあなたのロケールではen.yml:
en:
follow: "Follow, %{name}"
/カルステン
変数をその値に置き換える文字列補間を使用できます。
<div class="actions"><%= f.submit "Follow #{@user.name}" %></div>
便利なリンク: http: //en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation