Я работаю над приложением rails, в котором один пользовательский класс с именем (отправители) может войти в систему, и после входа в систему он создает видео. Контроллер моего видео находится здесь:
class VideosController < ApplicationController
def index
@videos = Video.find :all
end
def new
@submitter = current_submitter
@video = @submitter.videos.build
end
def create
@submitter = current_submitter
@video = @submitter.videos.build(params[:video])
if @video.save
@video.convert
flash[:notice] = 'Video has been uploaded'
redirect_to :action => 'index'
else
render :action => 'new'
end
end
def show
@video = Video.find(params[:id])
end
def destroy
@video = Video.find(params[:id])
@video.destroy
flash[:notice] = "Successfully deleted the video."
redirect_to root_url
end
def update_date
@video = Video.find(params[:id])
@video.update_attributes(params[:video])
flash[:notice] = "Successfully added a launch date!"
redirect_to @video
end
end
Как вы, вероятно, видите, я пытаюсь сконструировать контроллер так, чтобы при создании видео он создавался как принадлежащий отправителю, который загрузил видео (через новый вид видео). Я использую систему аутентификации с методом current_submitter, записанным в контроллере приложения.
Теперь он позволяет мне нормально загружать видео, когда я вошел в систему как отправитель. Беда для меня в том, чтобы решить, как отображать информацию в моем представлении. Если я хочу отобразить некоторые столбцы с информацией о видео, а затем другие с информацией о отправителе, который загрузил видео, как мне это сделать с контроллера (действие index) в представлении индекса. Мой текущий вид, который не работает ниже:
<% title "Films Submitted" %>
<table>
<tr>
<th>Title</th>
<th>Film Type</th>
<th>Premiere</th>
<th>Company</th>
<th>Name</th>
</tr>
<% for video in @videos do %>
<tr>
<td><%= link_to video.title, video %></td>
<td><%= video.film_type %></td>
<% if video.premiere == "true" %>
<td>Premiere</td>
<% else %>
<td><%= %></td>
<% end %>
<td><%= video.submitter.company %></td>
<td><%= video.submitter.name %></td>
<td><%= link_to "Delete", video, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>
<br><br>
<%= link_to "Upload a Video", new_video_path %>
Любые предложения или советы от разработчиков рельсов были бы очень благодарны ... Я новичок и пытаюсь учиться.
Модель видео:
class Video < ActiveRecord::Base
belongs_to :submitter
has_attachment :content_type => :video,
:storage => :file_system,
:max_size => 50.megabytes
end
Модель отправителя:
class Submitter < ActiveRecord::Base
acts_as_authentic
has_many :videos
end
Схема:
create_table "videos", :force => true do |t|
t.string "title"
t.text "description"
t.string "state"
t.datetime "created_at"
t.datetime "updated_at"
t.string "content_type"
t.integer "size"
t.string "filename"
t.string "film_type"
t.boolean "premiere", :default => false
t.date "preferred_date"
t.text "reason"
t.integer "submitter_id"
t.date "actual_date"
end
create_table "submitters", :force => true do |t|
t.string "name"
t.string "company"
t.string "email"
t.string "username"
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "video_id"
end