すべてのレールアプリケーションのページで、状況によって選択ボックスが変化します:window.location.hrefを使用して選択ボックスでオプションを選択するとユーザーをリダイレクトすると、ナビゲータのURLの最後のビットのみが変更されます
<% if session[:user_status]%>
<% if params[:office_id] %>
<%= select_tag "dash_select", options_for_select([["<i class='fa fa-lock select_icon' aria-hidden='true'></i>"+session[:user_status], session[:user_status]], ["all offices", "all"]]), class: "form-control custom-office-select wide main-select-bar" %>
<% elsif params[:account_asso_id] %>
<%= select_tag "dash_select", options_for_select([["<i class='fa fa-lock select_icon' aria-hidden='true'></i>"+session[:user_status], session[:user_status]], ["<i class='fa fa-globe' aria-hidden='true'></i>
all offices", "all"]], "all"), class: "form-control custom-office-select wide" %>
<% else %>
<%= select_tag "dash_select", options_for_select([["<i class='fa fa-lock select_icon' aria-hidden='true'></i>"+session[:user_status], session[:user_status]], ["<i class='fa fa-globe select_icon' aria-hidden='true'></i>all offices", "all"]], session[:user_status]), class: "form-control custom-office-select wide" %>
<% end -%>
<% elsif session[:user_status] %>
<%= select_tag "dash_select", options_for_select([session[:user_status], session[:user_status]]), class: "form-control" %>
<% else %>
<% end -%>
選択ボックスのオプションが選択されたときにトリガされるJSを記述しました。どのオプションが選択されたかによって、別のページにユーザーをリダイレクトします。私は選択ボックスで選択したオプションを変更すると
$(document).ready(function() {
$('select').niceSelect();
$("#dash_select").change(function(){
if ($(this).val() == "all") {
window.location.href = "association/account_assos/"+<%=session[:account_asso_id]%>+"/offices"
}
else if ($(this).val() == "admin"){
window.location.href = "association/account_assos/"+<%=session[:account_asso_id]%>
}
else if ($(this).val() == "employee"){
window.location.href = "https://stackoverflow.com/users/"+ <%=session[:user_id] %>
}
else {
var office_id = $(this).val();
window.location.href = "association/office/"+office_id;
}
});
});
、ナビゲータ内のURLは、実際に変更されたが、全体ではなく、URLを変更し、単に例えば「http://localhost:3000/」の上に構築するのではなく、最後の抑制されました/現在のURLのビットとその上に新しいURLを持つ建物。 「http://localhost:3000/association/account_assos/6/users」 との私は「管理者」への私の選択に変更しましょう、それが現在の「/ユーザ」の部分を取り除くでしょう:私は現在、上のだページのURLがある場合たとえば
URLと私を与えるit..whichの上に構築:どのように私は、全体のURLだけでなく、最後のビットを変更することができます
%>
?: http://localhost:3000/association/account_assos/6/association/account_assos/ <% =セッション[をaccount_asso_id]