Closed 1dolinski closed 4 years ago
Is this a helper method defined in app/helpers? I couldn't find any mention of it in the rinku repo.
If that's the case, I believe you will need to include your helper file (maybe include ::ApplicationHelper
) in the controller that is serving this view.
If it's really in Rinku, you might have to include ActionView::Helpers::TextHelper
in that controller probably...
And/or actually you might have to do this include in Commontator::ApplicationController
Yes, defined in app/helpers
require 'rails_rinku'
include ActionView::Helpers::TextHelper
module TextHelper
def rinku_link(text)
auto_link(text, :html => { :target => '_blank' })
end
end
Yeah you'll need something like Commontator::ApplicationController.include TextHelper
and probably also include this module in the controller that renders the view where the thread itself appears.
It is a little odd that you have include ActionView::Helpers::TextHelper
outside of the context of a module though. It's like you are including that module in main
?
Good catch, moved the include into the module. It seems like there might be a reason why the TextHelper is recognized on create but not on edit. I understand that the helper module is already autoloaded by rails, so it wouldn't need to be re-loaded in the controller.
Adding Commontator::ApplicationController.include ActionView::Helpers::TextHelper
to the bottom of the initializer doesn't seem to help
Hmm I think the problem is that the method is being defined in ::TextHelper, not ActionView::Helpers::TextHelper so try Commontator::ApplicationController.include ::TextHelper
instead. Or Commontator::ApplicationController.helper ::TextHelper
. Or change your module TextHelper
to module ActionView::Helpers::TextHelper
(no need to include it in that case).
I think Rails may keep gem controllers and helpers separate from the application's by default. Getting gem controllers to use app helpers has always been a little weird to me.
For sure and great, one of your solutions worked out -- thanks!
I added the following in my Commontator initializer
Commontator::ApplicationController.helper ::TextHelper
and then also stripped out the include in the helper
require 'rails_rinku'
module TextHelper
def rinku_link(text)
auto_link(text, :html => { :target => '_blank' })
end
end
I recently added an autolink gem (https://github.com/vmg/rinku)
On create a comment properly auto links.
On edit it errors out with an undefined method:
Btw, rinku_link is the correct helper method name
Perhaps this user was having a similar issue - https://github.com/lml/commontator/issues/55