http://apidock.com/rails/ActionView/Helpers/TagHelper/content_tag
app/helpers/application_helper.rb
changed the name of the is_sorted? method to sort_active?
scope - within the context of this thing (limited vision) (This is not JQuery)
all enumerable objects respond to each
each wants an array
Method any? http://apidock.com/ruby/Enumerable/any%3F
any?()
public
Passes each element of the collection to the given block. The method returns true if the block ever returns a value other than false or nil. If the block is not given, Ruby adds an implicit block of {|obj| obj} (that is any? will return true if at least one of the collection members is not false or nil.
%w{ant bear cat}.any? {|word| word.length >= 3} #=> true
%w{ant bear cat}.any? {|word| word.length >= 4} #=> true
[ nil, true, 99 ].any? #=> true
%w{ant bear cat}.any? {|word| word.length >= 4} #=> true
[ nil, true, 99 ].any? #=> true
params is a query string in a url or any data passed through the url- gets turned into a hash in ruby named params (url decoder)
Find list-group-item in bootstrap
http://getbootstrap.com/components/#list-group Contextual classes
Use contextual classes to style list items, default or linked. Also includes
.active
state.We used the
class list-group-item-success
and it is already styled!
app/helpers/application_helper.rb
def will_collapse?
unless params[:scopes]
" collapse"
end
end
def sort_active?(current_scope)
if params[:scopes] && params[:scopes].any? { |scope| scope == current_scope }
"list-group-item-success"
end
end
unless params[:scopes]
" collapse"
end
end
def sort_active?(current_scope)
if params[:scopes] && params[:scopes].any? { |scope| scope == current_scope }
"list-group-item-success"
end
end
if params[:scopes] && if it is nil or ...
app/views/crowdshops/_sidebar_sort.html.erb
<ul class="list-group panel-collapse <%= will_collapse? %>">
<li class="list-group-item <%= sort_active?("popular") %>">
<%= link_to "Popular", crowdshop_path(crowdslug, scopes: ["popular"]) %>
</li>
<li class="list-group-item <%= sort_active?("recent") %>">
<%= link_to "Recent", crowdshop_path(crowdslug, scopes: ["recent"]) %>
</li>
<%= render partial: "sidebar_tag", collection: current_crowdshop.tags.uniq %>
</ul>
<li class="list-group-item <%= sort_active?("popular") %>">
<%= link_to "Popular", crowdshop_path(crowdslug, scopes: ["popular"]) %>
</li>
<li class="list-group-item <%= sort_active?("recent") %>">
<%= link_to "Recent", crowdshop_path(crowdslug, scopes: ["recent"]) %>
</li>
<%= render partial: "sidebar_tag", collection: current_crowdshop.tags.uniq %>
</ul>
commit message:
Highlight sort box in the sidebar to differentiate
Highlight sort box in the sidebar to differentiate the tag so that the user knows how the products are currently being sorted. Creates two helper methods is_active? embeds code into the view which adds the class list-group-item-success will_collapse? makes sure the panel remains open (not collapsing) after sort Uses the class list-group-item-success which changes the background-color of the sort parameter so the user can identify that the items have been sorted. modified: app/helpers/application_helper.rb