Created
October 20, 2011 21:12
-
-
Save adambair/1302403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fake_select(parameter, collection, description="", preposition="") | |
| html = "<div class='fake_select'>" | |
| unless params[parameter].blank? | |
| html << "<a class='first_option'>#{preposition} #{params[parameter]} #{description}</a>" | |
| else | |
| html << "<a class='first_option'>#{preposition} #{collection.first} #{description}</a>" | |
| end | |
| html << "<ul class='fake_list'>" | |
| collection.each do |item| | |
| html << content_tag(:li) do | |
| link_to "#{item} #{description}", '#', data: item, rel: parameter | |
| end | |
| end | |
| html << "</ul></div>" | |
| html << hidden_field_tag(parameter, params[parameter]) | |
| html.html_safe | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fake_select(parameter, collection, description="", preposition="") | |
| html = "<div class='fake_select'>" | |
| html << "<a class='first_option'>#{preposition} " | |
| html << find_param(params[parameter], collection.first) | |
| html << " #{description}</a>" | |
| html << "<ul class='fake_list'>" | |
| html << build_list_items(colleciton, description) | |
| html << "</ul></div>" | |
| html << hidden_field_tag(parameter, params[parameter]) | |
| html.html_safe | |
| end | |
| def find_param(parameter, item) | |
| params[parameter].blank? ? params[parameter] : item | |
| end | |
| def build_list_items(items, description) | |
| items.collect do |item| | |
| content_tag(:li) {link_to "#{item} #{description}", '#', data: item, rel: parameter} | |
| end.join("\n") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment