Rails は初めてで、YouTube 用のシンプルなクライアントを作成しようとしています。Youtube_it gem を使用して、プレイリストの 1 つですべてのビデオを取得しています。次のコードを使用しています。
コントローラ:
class PlaylistsController < ApplicationController
def show
client = session[:client]
@playlist = client.playlist(params[:id])
@playlist.extend(BasePlaylist)
end
end
Youtube_it/Playlist.class 用に拡張するモジュール:
module BasePlaylist
extend ActiveModel::Naming
include ActiveModel::Conversion
def model_name
'Playlist'
end
def persisted?
false
end
end
プレイリスト/show.html.erb:
<h1><%= @playlist.title %></h1>
<%= render 'form' %>
プレイリスト/_form.html.erb:
<%= form_for(@playlist) do |f| %>
<% @playlist.videos.each do |video| %>
<div class="field">
<%= f.check_box_tag video.title %>
<%= f.label video.title %>
</div>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
私が得ているものは次のとおりです。
undefined method `model_name' for YouTubeIt::Model::Playlist:Class
私が上で行ったことは、Playlist オブジェクトを「ラップ」しようとしていますが、機能していないようです。何か案が?