Auto_html says block not supplied

2019-08-06 13:00发布

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 %>

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?

1条回答
闹够了就滚
2楼-- · 2019-08-06 13:56

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 => 'blank')

For soundcloud use

auto_html(str) { soundcloud }

查看更多
登录 后发表回答