CJ Fry
CJ Fry

Reputation: 25

doing something wrong with auto_html gem?

I am trying to use the auto_html gem to convert a submitted youtube link into an embed link. I'm not getting any response from auto_html. I'm sure it's something simple that I'm missing?

In my Gemfile:

gem "auto_html"

I added :video_html column to my link model. (here is the migration file)

class AddVideoHtmlToLink < ActiveRecord::Migration
  def change
add_column :links, :url_html, :string
  end
end

my scheema.rb looks like this:

  create_table "links", :force => true do |t|
t.integer  "user_id"
t.string   "url"
t.string   "title"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string   "url_html"

end

my link.rb model looks like this:

class Link < ActiveRecord::Base
  belongs_to :user
  belongs_to :admin
  has_many   :comments
  has_many   :votes

  validates :title, :url, :presence => true


  attr_accessible :title, :body, :url, :user_id, :url_html


  auto_html_for :url do
    html_escape
    image
    youtube(:width => 400, :height => 250)
    vimeo(:width => 400, :height => 250)
    link :target => "_blank", :rel => "nofollow"
    simple_format
  end
end

In my index.html.haml view, I've got:

%p
  = link_to link.title, link.url_html, :class => "youtube title_link"

Now when I submit this through the console:

Link.create(:title => 'test', :url => 'http://www.youtube.com/watch?v=a2LFVWBmoiw')

I just get exactly this returned and I don't get the :url converted into an embed code as in the example on the github page (https://github.com/dejan/auto_html)

Any idea what I'm missing? Any help or pointers in the right direction are much appreciated!

Upvotes: 0

Views: 1102

Answers (1)

Dejan Simic
Dejan Simic

Reputation: 8130

You're passing video_html as param, you should pass video. Try this in console:

Link.create(:title => 'test', :url => 'http://example.com', :video => 'http://www.youtube.com/watch?v=a2LFVWBmoiw')

Upvotes: 1

Related Questions