S
S
svernidub2014-02-08 18:48:31
Ruby on Rails
svernidub, 2014-02-08 18:48:31

How to fix Error with routing or route helper in Rails?

Doing non-REST routing in a Rails application:

get "/:id" => "offers#show", as: :offer, constraints: { id: /\d/ }
get "/:region_slug" => "offers#index", as: :region_offers, constraints: { region_slug: /[a-z]/ }
get "/:region_slug/:id" => "offers#show", as: :region_offer, constraints: { region_slug: /[a-z]/, id: /\d/ }
get "/:region_slug/:scope_slug" => "offers#index", as: :region_scope_offers,
    constraints: { region_slug: /[a-z]/, scope_slug: /[a-z]/ }
get "/:region_slug/:scope_slug/:id" => "offers#show", as: :region_scope_offer,
    constraints: { region_slug: /[a-z]/, scope_slug: /[a-z]/, id: /\d/ }

I use one of the routes in the view:
= link_to category.name, region_scope_offers_path(@region.slug, category.slug)

I am getting this error:
ActionView::Template::Error (No route matches {:controller=>"offers", :action=>"index", :region_slug=>"region1", :scope_slug=>"category1", :format=>nil} missing required keys: [:region_slug, :scope_slug])

Tell me what could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
himik, 2014-02-08
@svernidub

{ region_slug: /[az]/, scope_slug: /[az]/ }
regular expression only for letters, there are also numbers in the passed variables,
replace with
{ region_slug: /[a-z0-9]/, scope_slug: /[a-z0 -nine]/ }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question