如果 link_to 在新页面上被点击闪现消息?
If link_to is clicked flash message on new page?
查看
<% 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")
查看
<%= 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 %>
查看
<% 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")
查看
<%= 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 %>