Rails route -> if no data, check another route -
i have route
match ":id", :to => "doctors#show", :via => :get, :as => :doctor match ":id", :to => "doctors#update", :via => :put, :as => :doctor
which gives me:
http://domain.com/id
now, created controller want have routes same previous.
match ":id", :to => "professions#show", :via => :get, :as => :profession
which gives me:
http://domain.com/id
but, want create checking system, example: if first route didn't found data, go , check one. definetly won't same @ time.
this show code in controller:
def show @profession = profession.find_by_slug(params[:id]) end
exception handling job of controller not routing.
to rescue no record error
class applicationcontroller < actioncontroller::base rescue_from activerecord::recordnotfound, with: :record_not_found private def record_not_found render text: "404 not found", status: 404 end end
http://guides.rubyonrails.org/action_controller_overview.html#the-default-500-and-404-templates
Comments
Post a Comment