2012-11-14 2 views
0

제출 된 YouTube 링크를 소스 링크로 변환하기 위해 auto_html gem을 사용하려고합니다. auto_html에서 응답이 없습니다. 내가 놓친 게 뭔가 간단하다고 확신하니? 내 Gemfile에auto_html gem에 문제가 있습니까?

는 :

gem "auto_html" 

나는 추가 : VIDEO_HTML 열을 내 링크 모델.

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

내 scheema.rb은 다음과 같습니다 (여기 마이그레이션 파일) :

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" 

내 link.rb 모델은 다음과 같습니다

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 

내 index.html.haml보기에는 다음이 있습니다.

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

는 지금은 콘솔을 통해이 문제를 제출할 때 :

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

난 그냥이 반환 정확하게 얻을 나는하지 않는다 다음 GitHub의 페이지의 예에서와 같은 소스 코드로 변환 URL을 (https://github.com/dejan/auto_html)

내가 무엇을 놓치고 있는지 알 수 있습니까? 올바른 방향으로 도움이나 조언을 많이 주시면 감사하겠습니다!

답변

1

param으로 video_html을 전달하면 동영상을 전달해야합니다. 콘솔에서 사용해보세요.

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

답장을 보내 주셔서 감사합니다. 이해가 부족하다는 것을 용서하지만, 콘솔에서이 오류가 발생했습니다 : ruby-1.9.2-p290 : 033> Link.create (: title => 'test', : url => 'http : // example .com ', : video =>'http://www.youtube.com/watch?v=a2LFVWBmoiw ') ActiveRecord :: UnknownAttributeError : 알 수없는 속성 : 비디오 –

+0

아! 방금 당신의 스키마를 확인했습니다. 데이터베이스에 video 및 video_html이 필요합니다. 그것이 작동하는 방법입니다. 동영상은 사용자의 원시 입력이며 video_html은 형식이 지정된 마크 업으로 페이지에 표시됩니다. –

+0

좋아요, 그래서 위 내용을 수정하여 변경 사항을 반영했습니다. 이미 데이터베이스에 URL이있어 : 대신 비디오를 사용할 수 있습니까? 이 경우 auto_html_for가 될 것입니다 : 내가 수정 한 내용을 반영한 url입니까? –

관련 문제