ruby on rails - Routes with optional parameters -


following attempt seems functional, not 'clean' result trying archive.

following route

get "/learn(/:category)", to: "users#index", as: "learn" 

should useable "/learn/technology" - works, if entered manually in address bar.

if tough try achieve similar in views, following: "/learn?category=technology" - well, technically works, not want.

i'm using following inside view:

- category.promoted.limit(7).each |category|   %li.category-button     = link_to learn_path(category)       = button_tag "", :class => "#{category.name}"       = content_tag(:span, category.to_s, :class => 'category-head') 

and category model looks following:

class category < activerecord::base   has_many :skills    validates_uniqueness_of :name    scope :promoted, lambda { where(:promoted => true) }    def to_s     read_attribute(:name).titleize   end    def to_param     name.parameterize   end end 

how achieve 'cleaner' solution?

edit:

following works - there must better solution that?

get "/learn", to: "users#index", as: "learn"   "/learn/:category", to: "users#index", as: "filter_learn" 

try changing link following:

... = link_to learn_path(category: category.name) ... 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -