Mateusz Urbański
Mateusz Urbański

Reputation: 7862

How to pull out all routes for specific resource

I have strange question. I want in my helper to have array of paths that are available for specific resource.For example, if we have a model Comment I want to have an array which will have the following elements: [new_comment_path, comments_path] etc. Is this possible to do?

Edit: I build left side menu in rails. It will work like tree menu. I don't want to use external plugins. Only thing that i must do is to have a all paths for my models.

Upvotes: 0

Views: 31

Answers (1)

j-dexx
j-dexx

Reputation: 10406

You can do

Rails.application.routes.routes.map{|x| x.name}.reject{|x| x.blank?}

Which will get all named routes. I'm not sure if there is a way of just getting routes for one resource though

Upvotes: 2

Related Questions