Category: Rails

Rails Admin: Conditionally display a field based on a specific object’s value

To conditionally display a field based on a value in the displayed object, you can do the following: RailsAdmin.config do |config| config.model YourObject do edit do field :some_random_attribute do visible do bindings[:object].your_conditional_field==”your_conditional_value” end end end end end   In this Rails Admin configuration example, you can see that the YourObject#some_random_attribute field will only display if […]

Rails Admin Custom Dashboard

To create a custom rails_admin dashboard, first create a new file here: lib/rails_admin.rb   And in your rails_config/initializers/rails_admin.rb initializer file, be sure to include the above file: RailsAdmin.config do |config| require Rails.root.join(‘lib’, ‘rails_admin.rb’) end   Within this new file, do the following: module RailsAdmin module Config module Actions class Dashboard < RailsAdmin::Config::Actions::Base RailsAdmin::Config::Actions.register(self) register_instance_option :root? […]

Rails conditional migrations – ensure column does not exist

If you’re running into a rails migration exception, such as: column “x” of relation “y” already exists Then you can conditionally run the associated migration in the following way: YourModel.reset_column_information unless YourModel.column_names.include?(“the_column”) add_column(:your_models, :the_column, :boolean, :default=>true) end   Of course, it is probably best to address the underlying workflow issues that caused this issue to […]

Rails 4, Carrierwave, Remote file url uploading

If you’re running into the following error when attempting to use Carrierwave to upload a remote file url: TypeError: no implicit conversion of nil into String Then you’re probably very frustrated at the moment. I dug into the carrierwave gem to figure the issue out exactly, however I realized there was an easier (and much […]

Sunspot Solr – Indexing PDF documents

Indexing PDF documents using sunspot / solr seemed like a difficult task initially. There are a number of tutorials dealing with this topic but they seemed overly complicated. In the end, I decided the simplest way to go about providing search functionality for indexed PDF documents was to 1) parse the documents locally 2) input […]

Rails remote multipart form with remotipart bind ajax:success

Rails 3.x / 4.0 does not handle remote multipart forms natively, so a workaround is needed. To get remote multipart forms working correctly you can use the following steps (quick solution). First: Add the remotipart gem to your GemFile gem ‘remotipart’, ‘~> 1.2.1’ Then, Update your javascript manifest file (in basic configurations this is usually […]