问题描述
我有一个网站,允许用户发布链接。我试图获取soundcloud链接来嵌入媒体文件,因此尝试使用AutoHtml Gem。我完成了gem install Autohtml的安装,将其放在我的gemfile和config / application.rb中,并进行了捆绑安装。为什么Auto_html()无法正常工作。
I have a website that allows users to post links. I am trying to get the soundcloud links to embed the mediafile thus I am attempting to use AutoHtml Gem. I did gem install Autohtml, put it in my gemfile and in config/application.rb and ran bundle install. Why isn't Auto_html() working.
GEMFILE
source 'https://rubygems.org'
gem 'rails', '3.2.8'
gem 'bootstrap-sass', '2.0.4'
gem 'bcrypt-ruby', '3.0.1'
gem 'faker', '1.0.1'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate', '0.0.6'
gem 'jquery-rails', '2.0.2'
gem 'pg', '0.12.2'
gem 'rails_autolink', '~> 1.0.9'
gem 'rinku', '~> 1.5.0', :require => 'rails_rinku'
gem 'auto_html', '1.6.0'
CONFIG/APPLICATION.RB
require File.expand_path('../boot', __FILE__)
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"
require "sprockets/railtie"
require "rails_autolink"
require "rails_rinku"
require "auto_html"
VIEW/MICROPOSTS/_MICROPOST.HTML.ERB
<% if micropost.url.include? 'soundcloud' %>
<%= auto_html(micropost.url) %>
<% end %>
抱歉,我对Ror是陌生的人,感谢您的帮助。我只想在这里特别针对Soundcloud使用Auto_html。我忘了做什么?
Sorry for the ignorance I'm new to Ror I appreciate the help. I only want to Auto_html here for soundcloud in particular. What am I forgetting to do?
推荐答案
这是辅助方法,因此需要以下几行:
It is helper method, so you'll need the following lines:
# app/helpers/application_helper.rb
module ApplicationHelper
include AutoHtml
end
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base # or something like that
helper ApplicationHelper
end
编辑,如果您阅读了该页面,则会看到一个示例块:
Edit if you read the page, there's an example block given: https://github.com/dejan/auto_html
auto_html(str){simple_format; link(:target =>'空白')
用于soundcloud
For soundcloud use
auto_html(str){soundcloud}
这篇关于Auto_html表示未提供阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!