2016-11-05 16 views
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")

+1

私はあなたが従来間違ってやろうとしているし、代わりにフォームを使用して行われるべきものだと思います。 –

+0

あなたのページにdisplay flash message partialを追加しましたか? – user100693

+0

@AkashAggarwalたぶん私は 'performance_with_flash'というページにリダイレクトするべきですが、フラッシュメッセージを追加するために重複したコードがたくさんあるかもしれないと思います。 –

答えて

1

ビュー

を試してみました
<%= link_to performance_path(alert: true), class: "btn", style: "padding-top: 10px; padding-bottom: 10px; margin-top: 15px; color: white;" do %> 
    <span class='glyphicon glyphicon-tower'></span> Duel 
<% end %> 

コントローラ

def performance 
    @user = current_user 
    flash[:alert] = "YOU'RE NOT AUTHORIZED TO INITIATE A DUEL UNTIL YOU BECOME A NINJA, BUT YOU CAN BE INVITED TO A DUEL" if params[:alert].present? 
end 

パフォーマンス・ビュー

<% if flash[:alert] %> 
    <%= flash[:alert] %> 
<% end %>