-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Hi Guys,
I'm looking for a way to use the id instead of the slug in certain path helpers.
Namely I want admin_posts_path post to generate /admin/posts/2 and not /admin/posts/my-cool-post
So far I have come up with a ugly solution of overriding the to_param for each model in the admin controller and then back again..
class Admin::AdminController < ApplicationController
before_action :dont_slug
after_action :do_slug
private
def dont_slug
Post.class_eval do
def to_param
self.id.to_s
end
end
end
def do_slug
Post.class_eval do
def to_param
self.cached_slug.to_s
end
end
end
endBut this is really ugly when you have 10 models using slugs.
I do know I could override each of the path helpers... but I have hundreds of paths and adding one for each route is prone to errors.
Any help with a better work-around would help me a lot!
Thanks!
Metadata
Metadata
Assignees
Labels
No labels