我正在嘗試獲取一系列工作鏈接。有些應該是可切換的,有些則不可以。鏈接和參數
基本上在頁面刷新我的PARAMES散列已經有兩個鍵,它不應該有,我不能看到他們在哪裏被添加。
我的鏈接:
<ul class="all filter__group">
<li><%= link_to "View all", coasters_path(page: 1), remote: true %></li>
</ul>
<ul class="types filter__group">
<%= content_tag(:li, class: ("active" if params[:type] == "steel")) do %>
<%= link_to "Steel", coasters_path(type_parameters("steel", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:type] == "wood")) do %>
<%= link_to "Wood", coasters_path(type_parameters("wood", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:type] == "powered")) do %>
<%= link_to "Powered", coasters_path(type_parameters("powered", page: 1)), remote: true %>
<% end %>
</ul>
<ul class="letters filter__group">
<%= content_tag(:li, class: ("active" if params[:letters] == "#")) do %>
<%= link_to "#", coasters_path(letter_parameters("#", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:letters] == "a-e")) do %>
<%= link_to "A-E", coasters_path(letter_parameters("a-e", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:letters] == "f-j")) do %>
<%= link_to "F-J", coasters_path(letter_parameters("f-j", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:letters] == "k-o")) do %>
<%= link_to "K-O", coasters_path(letter_parameters("k-o", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:letters] == "p-t")) do %>
<%= link_to "P-T", coasters_path(letter_parameters("p-t", page: 1)), remote: true %>
<% end %>
<%= content_tag(:li, class: ("active" if params[:letters] == "u-z")) do %>
<%= link_to "U-Z", coasters_path(letter_parameters("u-z", page: 1)), remote: true %>
<% end %>
</ul>
<%= debug params %>
的輔助方法:
# Add the type parameter to URL if not already there and remove if they are
def type_parameters(type, options = {})
parameters = {}
if params[:type] == type
# Get exisiting params
parameters = params
# Remove type
parameters.delete(:type)
# Merge any parameters passed in via options
parameters.merge!(options)
else
# Get exisiting params
parameters = params
#Add type to new parameters variable
parameters.merge!(type: type)
# Merge any parameters passed in via options
parameters.merge!(options)
end
parameters
end
# Add the letters parameter to URL if not already there and remove if they are
def letter_parameters(letters, options = {})
parameters = {}
if params[:letters] == letters
# Get exisiting params
parameters = params
# Remove letters
parameters.delete(:letters)
# Merge any parameters passed in via options
parameters.merge!(options)
else
# Get exisiting params
parameters = params
#Add letters to new parameters variable
parameters.merge!(letters: letters)
# Merge any parameters passed in via options
parameters.merge!(options)
end
parameters
end
在一個頁面重新加載,這是當前PARAMS哈希:
--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
action: index
controller: coasters
type: powered
page: 1
letters: u-z
在哪裏,我錯了任何想法?
你能不能給我們的控制器操作的新副本? –
控制器操作:https://gist.github.com/anonymous/8383369 – rctneil
你確定沒有重新載入包含'letters = u-z'的URL嗎? –