12

I am using ActionText to edit a paragraph and it works perfectly locally but when I deploy it to Heroku the page which has the form with rich_text_area it throws an error saying undefined method rich_text_area_tag even though I followed the rails guide. I thought I needed to configure Active Storage on production but that's not the case.

Here is what I am getting in Heroku's logs: ActionView::Template::Error (undefined method 'rich_text_area_tag' for #<#<Class> Did you mean? rich_text_area)

<%= f.label :something, class:'label' %>
<%= f.rich_text_area :something %>
Grofen
  • 153
  • 8
  • Your error says `undefined method 'rich_text_area_tag'`, but your code only have `rich_text_area`. Did you update it with just `f.rich_text_area`? –  Aug 23 '19 at 17:53
  • @allenbrkn thanks for your comment, I have it in the code as `f.rich_text_area` but I don't know why does it add **tag**, if you mean I should delete `:something` that will cause error. – Grofen Aug 24 '19 at 00:52
  • Did you try running commands like `heroku run bundle exec rake db:migrate`, `heroku run bundle exec rake assets:precompile` after deploying? –  Aug 24 '19 at 03:45
  • @allenbrkn I tried both of them but nothing changed still getting the same error. – Grofen Aug 26 '19 at 10:52
  • Can you run `heroku run rails -v` and `heroku run ruby -v` and see if Heroku is using your preferred Rails/Ruby version. Most of the time it will use properly, but just in case. Also, can you update your complete `form` code? –  Aug 27 '19 at 07:27
  • @allenbrkn Rails version on Heroku is `Rails 6.0.0` and Ruby version is `ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]` The form code here: `<%= form_with(scope: chapter, url: chapter_path(chapter), method: "put", local: true) do |f| %> <%= f.label :something, class:'label' %> <%= f.rich_text_area :something %> <% end %>` – Grofen Aug 27 '19 at 15:31
  • Don't know what's causing the error. But can you try changing `scope: chapter` to `scope: :chapter`? –  Aug 28 '19 at 13:01

3 Answers3

16

I found this online, and it was helpful for me:

https://github.com/JoeWoodward/spree_helper_issue

I am not sure if this is the correct way to do it, but it's a temporary workaround.

SOLUTION:

In application_controller.rb enter the following:

require 'action_text'

class ApplicationController < ActionController::Base
  helper ActionText::Engine.helpers

  ...
end

Docs for helper: https://apidock.com/rails/AbstractController/Helpers/ClassMethods/helper

jethro
  • 168
  • 3
  • 13
Violeta
  • 700
  • 7
  • 16
3

First of all make sure that you have this line in config/application.rb:

require 'rails/all'

If it's a rails 6 app action_text/engine should be loaded.

If it doesn't it's possible taht zeitwerk is not loaded. This happens when you have a rails 5.2 app that was updated to rails 6.

In the same file (config/application.rb) you have to change config.load_defaults to 6.0:

config.load_defaults 6.0

If you want to know what happens in the background take a look at this link on line 125.

TopperH
  • 2,183
  • 18
  • 33
  • 1
    Thank you for taking the time to look at it, so I checked `config/application.rb` I have these two lines `require 'rails/all'` and `config.load_defaults 6.0` the only solution which worked for me is that I had to add `require 'action_text'` but I ended up adding trix-editor tag manually. @TopperH – Grofen Sep 18 '19 at 13:57
  • Are you for some reasons not using zeitwerk? – TopperH Sep 19 '19 at 14:38
  • I have `config.autoloader = :zeitwerk` in `config/application.rb` @TopperH – Grofen Sep 20 '19 at 10:33
1

To avoid cluttering the ApplicationController code, you can use an initializer:

i.e. add a new file config/initializers/action_text.rb:

ActiveSupport.on_load(:action_view) do
  include ActionText::ContentHelper
  include ActionText::TagHelper
end

Inspired by p8's comment in a closed Rails issue.

Puffo
  • 75
  • 8