Git Product home page Git Product logo

Comments (9)

spohlenz avatar spohlenz commented on May 21, 2024 6

It is now possible to properly remove an action using the remove_action builder method. Relevant buttons (e.g. save, delete, etc) will also be removed when removing an action.

Usage:

Trestle.resource(:articles) do
  remove_action :destroy, :edit, :update
end

from trestle.

hdbreaker avatar hdbreaker commented on May 21, 2024 2

Hi, is possible to call remove_action :destroy, :edit, :update inside an if statement? I want to remove actions based on user roles (devise).

Something like:

if not current_user.admin?
   remove_action :destroy, :edit, :update
end

Regards,

from trestle.

pandabamboo90 avatar pandabamboo90 commented on May 21, 2024 1

@hdbreaker

Yes you can do that

actions do |toolbar, user|
  toolbar.edit if user.role_user?
  toolbar.delete if user.role_user?
end

from trestle.

skiggety avatar skiggety commented on May 21, 2024 1

OK, I figured out that I could put that 'actions do' block inside 'table do', but not inside the form.

from trestle.

spohlenz avatar spohlenz commented on May 21, 2024

At present, the options are to either make the entire resource read only, using Trestle.resource(:name, readonly: true) do, or to disable the destroy action using:

controller do
  undef_method :destroy
end

However this won't remove the delete links (yet).

I am currently working on an API for custom actions which will allow the default actions to be disabled. I may be able to get that part out sooner than the rest.

from trestle.

martio avatar martio commented on May 21, 2024

Thx! 👍

from trestle.

svoboda-jan avatar svoboda-jan commented on May 21, 2024

Using remove_action :show causes ActionController::UrlGenerationError.

from trestle.

svoboda-jan avatar svoboda-jan commented on May 21, 2024

Workaround for ActionController::UrlGenerationError when using remove_action :show:

table autolink: false do
  # ...
end

from trestle.

skiggety avatar skiggety commented on May 21, 2024
actions do |toolbar, user|
  toolbar.edit if user.role_user?
  toolbar.delete if user.role_user?
end

Where does that go?

from trestle.

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.