查看
<% 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
发送Flash,但没有任何结果:link_to performance_path(:alert => "Flash message")
也尝试(:error => "Flash message")
答案 0 :(得分: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 %>