I have a vimeo account that I would like to link the videos from my account to posts in my rails app.
I have the Vimeo Gem and I'm having difficulty understanding how I implement the API within my post.
For each post created I want to link a video file to the post based on a column from my database which I input the video id.
Does anyone know of any tutorials or example regarding this gem?
Schema
create_table "vimeo", :force => true do |t|
t.string "title"
t.text "description"
t.integer "vimeo_clip_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Controller
Show
@vimeo = Vimeo.find(params[:id])
@video = Vimeo.where(:vimeo_clip_id)
@vimeo = Vimeo::Simple::Video.info(@video)
View
<p><%= @vimeo.title %></p>
Outputs 'video_id is not a valid method.'.
Not sure how to implement the API so it recognises my Vimeo user id and then displays the video as per my video_clip_id I input.
You have to replace video_id
with the vimeo_clip_id
value. For example in the console
Vimeo::Simple::Video.info "78673338"
returns
<HTTParty::Response:0x7ff09a9076e8 large_chunk_of_data_here>
You can create the link you want with the data you receive. In your controller:
def show
@vimeo = Vimeo.find params[:id]
@link_url = Vimeo::Simple::Video.info(@vimeo.vimeo_clip_id)[0]['url']
end
and in the view:
link_to @vimeo.title, @link_url
Please note the following:
[0]['url']
part does.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.