In rails_admin, how do I turn off the "add new" and "edit" button in relation sub-foms?
Asked Answered
N

4

16

I want to stop people adding or editing Page Layout from inside a sub form. Basically I want to turn off the buttons in the below screenshot:

enter image description here

Am I able to do this, or do I have to turn off adding and editing on the entire Page Layout model globally?

Nog answered 4/10, 2012 at 15:49 Comment(0)
T
31

Probably a bit late but you can use inline_add and inline_edit.

Example:

  field :profile do
    inline_add false
    inline_edit false
  end
Tinsley answered 2/10, 2013 at 21:20 Comment(1)
This is very nice. Is there any way to do it for all fields?Beedon
C
0

Use button_to with :disabled => true option

Churchlike answered 4/10, 2012 at 17:54 Comment(0)
D
0

Maybe not the cleanest solution... anyway here's what i did. Created an alternative partial copying the original one and stripping off the links related to "add new" and "edit". Then I configured the field like this.

  field :operator_user do
    partial "form_filtering_select_no-relations"
    def selected_id
      @bindings[:object]['operator_user_id']
    end
  end

The partial expects a method called "selected_id" to be there and return the id used to build the relation.

Durga answered 13/12, 2012 at 18:2 Comment(0)
C
-2

Supposing you are talking about authorizing a specific type of user to "see" the buttons you can go with the cancan gem.

Choriocarcinoma answered 4/10, 2012 at 16:9 Comment(5)
Yeah I found cancan, but I thought it might be overkill. I just want to turn off those particular buttons for all users.Nog
For all users? why don't you just remove the buttons then?Choriocarcinoma
Yep that's what I'm asking how to do!Nog
Go the that page view and remove the buttons. Also remove the routes so no one can call the actions.Choriocarcinoma
any other solutions except cancan?Hendley

© 2022 - 2024 — McMap. All rights reserved.