Code Monkey home page Code Monkey logo

Comments (8)

sbeam avatar sbeam commented on May 14, 2024 2

I found a way to do this that leverages i_r's :finder option on the controller. I am using stringex and have a slug column on the Model. So

ActiveAdmin.register Category do
    controller do
        defaults :finder => :find_by_slug
    end
end

from activeadmin.

gregbell avatar gregbell commented on May 14, 2024

You should be able to implement this using the to_param and using a before filter in the resource.

I haven't actually tested this, so let me know if this works... But it should look something like this.

class Post < ActiveRecord::Base
  def to_param
    uuid
  end
end

ActiveAdmin.register Post do

  before_filter :only => [:show, :edit, :update] do
    @post = Post.find_by_uuid(@post)
  end

end

Active Admin should use the @post variable instead of looking it up if you have already defined it.

Again, I haven't had a chance to test this out, but we use this method for show screens in our app. I'm assuming it will work for the edit and update.

Let me know how it goes.

from activeadmin.

jeffrafter avatar jeffrafter commented on May 14, 2024

Actually this should read:

before_filter :only => [:show, :edit, :update] do
   @post = Post.find_by_uuid!(params[:id])
end

Adding the ! gives you the nice 404 behavior, and @post is not defined at this point, params[:id] is.

from activeadmin.

gregbell avatar gregbell commented on May 14, 2024

@malyk did this work for you?

from activeadmin.

MikeAbner avatar MikeAbner commented on May 14, 2024

Greg

I actually never tried it. Got caught up on other things. If I do give it another go (which I do want to do when time permits) I'll let you know. Thanks for looking into it.

from activeadmin.

gregbell avatar gregbell commented on May 14, 2024

Cool. Thanks @malyk

from activeadmin.

makvool avatar makvool commented on May 14, 2024

thanks @sbeam, worked like a charm

from activeadmin.

mitchwd avatar mitchwd commented on May 14, 2024

Thanks @sbeam. Was looking for a while!

from activeadmin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.