Auto_html表示未提供块

时间:2012-12-12 01:42:40

标签: ruby-on-rails ruby embed soundcloud

我有一个允许用户发布链接的网站。我试图获得soundcloud链接嵌入媒体文件因此我试图使用AutoHtml宝石。我做了宝石安装Autohtml,把它放在我的gemfile和config / application.rb中并​​运行bundle install。为什么Auto_html()不起作用。

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的新手,我很感激帮助。我特别想在声音云中使用Auto_html。我忘记做什么了?

1 个答案:

答案 0 :(得分:1)

这是辅助方法,因此您需要以下几行:

# 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

编辑如果您阅读了该页面,则会给出一个示例块:https://github.com/dejan/auto_html

auto_html(str) { simple_format; link(:target => 'blank')

使用soundcloud

auto_html(str) { soundcloud }