将URL添加到数据库Rails

时间:2013-11-12 01:03:56

标签: ruby-on-rails ruby-on-rails-3.2

我有一个使用vimeo gem的rails应用程序。我想为每个创建的视频添加缩略图地址,并将链接添加到数据库,这样我就可以在我的索引视图上对image_tag进行image_tag,但我不确定如何在创建每个视频文件时将url保存到我的数据库中。

我可以轻松地访问我的节目页面上的'thumbnail_small',但不能在我的索引上调用它,所以我认为最好将网址保存到我的数据库中。

索引视图

<h1>Videos</h1>
<hr>
<% @videos.each do |videos| %>
<%= link_to (image_tag videos.thumb), video_path(videos) %>
<% end %>

视频控制器

def index
 @videos = Video.all
  end

def show
 @video = Video.find(params[:id])
 @vimeo = Vimeo::Simple::Video.info(@video.vimeo_clip_id)[0]['id']
 end

def new
 @video = Video.new :thumb => @thumb
 @thumb = Vimeo::Simple::Video.info(@vimeo.vimeo_clip_id)[0]['thumbnail_small']
end

模式

  create_table "video", :force => true do |t|
    t.datetime "created_at",    :null => false
    t.datetime "updated_at",    :null => false
    t.string   "title"
    t.text     "description"
    t.integer  "vimeo_clip_id"
    t.string   "thumb"
  end

2 个答案:

答案 0 :(得分:0)

也许我误解了,但似乎你只是将URL保存为字符串。     t.string“url”

答案 1 :(得分:0)

我已经解决了这个问题。创建帖子后,我使用update_attribute调用来更新数据库。