0
ビューlink_toをクリックすると新しいページでフラッシュメッセージが表示されますか?
<% if current_user.challenges.badges.count > 0 %>
<%= link_to new_duel_path(:challenge_daddy => @user.id), class: "btn", style: "padding-top: 10px; padding-bottom: 10px; margin-top: 15px; color: white;" do %>
<span class='glyphicon glyphicon-tower'></span> Duel
<% end %>
<% else %>
# user will be sent to performance page
<%= link_to performance_path, class: "btn", style: "padding-top: 10px; padding-bottom: 10px; margin-top: 15px; color: white;" do %>
<span class='glyphicon glyphicon-tower'></span> Duel
<% end %>
<% end %>
コントローラ
def performance
@user = current_user
# only if the user is brought to performance via the above link_to should this be flashed
flash[:alert] = "YOU'RE NOT AUTHORIZED TO INITIATE A DUEL UNTIL YOU BECOME A NINJA, BUT YOU CAN BE INVITED TO A DUEL"
end
私はlink_to
に直接フラッシュを送信しようとしましたが、何も起こらなかっ:link_to performance_path(:alert => "Flash message")
も(:error => "Flash message")
私はあなたが従来間違ってやろうとしているし、代わりにフォームを使用して行われるべきものだと思います。 –
あなたのページにdisplay flash message partialを追加しましたか? – user100693
@AkashAggarwalたぶん私は 'performance_with_flash'というページにリダイレクトするべきですが、フラッシュメッセージを追加するために重複したコードがたくさんあるかもしれないと思います。 –