nessboy
nessboy

Reputation: 15

Using custom JQuery in Rails Admin [rails 6]

My application uses 'rails_admin' and I would like every page within '/admin' to have a custom javascript file.

rails version: 6

EDIT:

My example I want to remove all these comments on each model, when I go to 'add new'.

All of these are <span class = 'help-block'>...</span> so I thought about using document.getElementsByClassName("help-block").style.visibility = "hidden"; it to solve my problem.

But it did not work.

Upvotes: 0

Views: 762

Answers (3)

Dyllan
Dyllan

Reputation: 21

To turn off the 'comments' for the whole model, use the following code in your rails_admin.rb file:

config.model "ModelName" do

  edit do
    fields do
      help false
    end
  end

end

Upvotes: 0

Guillermo Siliceo Trueba
Guillermo Siliceo Trueba

Reputation: 4619

Rails admin has a way to remove those "comments" for example if you place this code any of your models

rails_admin do
  edit do
    field :name do
      help do
        nil
      end
    end
  end
end

Its kind of annoying to do it for every field, but repetition in configuration is one of rails_admin weaknesses

Upvotes: 1

Guillermo Siliceo Trueba
Guillermo Siliceo Trueba

Reputation: 4619

Create this file on your project directory, create the folders if needed:

/app/assets/javascripts/rails_admin/custom/ui.js

Then place this content on the file

//= require_tree .
let yourjavascript = 'whatever you want'

Rails admin will import it this file on every page.

You might need to clear your assets pipeline depending on your configuration

rake tmp:clear

Upvotes: 0

Related Questions