Auto_link 与rails_autolink gem - 未定义的方法
我正在尝试使用rails_autolink gem。 像往常一样,我将 gem 声明添加到我的 gemfile 中:
gem 'rails_autolink'
然后运行“bundle install”,重新启动我的 Rails 本地服务器并 然后,我在类声明之前将 require 添加到 posts_controller 中
require 'rails_autolink'
class PostsController < ApplicationController
...
,并在创建操作中使用 auto_link 方法。
def create
@new_post = Post.new(params[:post])
if @new_post.content == ""
redirect_to posts_url
else
@new_post.content = auto_link(@new_post.content)
... #respond_to and save methods
end
end
end #end of my post controller
事情是,当我尝试创建帖子时,我在 auto_link 方法上有一个未定义的方法,知道为什么吗?是宝石特有的还是其他原因?
I'm trying to use the rails_autolink gem.
As usual, I added the gem declaration to my gemfile:
gem 'rails_autolink'
Then ran "bundle install", restarted my rails local server and
Then I added to my posts_controller the require before the class declaration
require 'rails_autolink'
class PostsController < ApplicationController
...
and used the auto_link method inside my create action
def create
@new_post = Post.new(params[:post])
if @new_post.content == ""
redirect_to posts_url
else
@new_post.content = auto_link(@new_post.content)
... #respond_to and save methods
end
end
end #end of my post controller
The thing is that when I try to create a post I have a undefined method on the auto_link method, any idea why ? Is it specific to the gem or is it because something else ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是您尝试在控制器中使用的视图助手
This is a view helper which you're trying to use in a controller
在任何其他地方您可以使用:
ActionController::Base.helpers.auto_link(text)
In any other places you can use:
ActionController::Base.helpers.auto_link(text)
我不相信你需要命名空间。只需使用以下命令再试一次:
I don't believe you need the namespacing. Try it again simply using: