Load videos through answer in all actions
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseController
|
||||
before_action :load_answer, only: [:index, :new, :create]
|
||||
before_action :load_video, only: [:edit, :update, :destroy]
|
||||
load_resource :answer, class: "::Poll::Question::Answer"
|
||||
load_resource class: "::Poll::Question::Answer::Video", through: :answer
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@video = ::Poll::Question::Answer::Video.new
|
||||
end
|
||||
|
||||
def create
|
||||
@video = ::Poll::Question::Answer::Video.new(video_params)
|
||||
|
||||
if @video.save
|
||||
redirect_to admin_answer_videos_path(@answer),
|
||||
notice: t("flash.actions.create.poll_question_answer_video")
|
||||
@@ -25,7 +22,7 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
|
||||
def update
|
||||
if @video.update(video_params)
|
||||
redirect_to admin_answer_videos_path(@video.answer), notice: t("flash.actions.save_changes.notice")
|
||||
redirect_to admin_answer_videos_path(@answer), notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@@ -34,7 +31,7 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
def destroy
|
||||
@video.destroy!
|
||||
notice = t("flash.actions.destroy.poll_question_answer_video")
|
||||
redirect_to admin_answer_videos_path(@video.answer), notice: notice
|
||||
redirect_to admin_answer_videos_path(@answer), notice: notice
|
||||
end
|
||||
|
||||
private
|
||||
@@ -44,14 +41,6 @@ class Admin::Poll::Questions::Answers::VideosController < Admin::Poll::BaseContr
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
[:title, :url, :answer_id]
|
||||
end
|
||||
|
||||
def load_answer
|
||||
@answer = ::Poll::Question::Answer.find(params[:answer_id])
|
||||
end
|
||||
|
||||
def load_video
|
||||
@video = ::Poll::Question::Answer::Video.find(params[:id])
|
||||
[:title, :url]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
<%= render "shared/errors", resource: @video %>
|
||||
|
||||
<%= f.hidden_field :answer_id, value: @video.answer_id || @answer.id %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_video_path(@video) %>
|
||||
<%= render "form", form_url: admin_answer_video_path(@answer, @video) %>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</h2>
|
||||
|
||||
<%= link_to t("admin.answers.videos.index.add_video"),
|
||||
new_admin_answer_video_path,
|
||||
new_admin_answer_video_path(@answer),
|
||||
class: "button success float-right" %>
|
||||
|
||||
<div>
|
||||
@@ -22,7 +22,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @answer.videos.each do |video| %>
|
||||
<% @videos.each do |video| %>
|
||||
<tr id="<%= dom_id(video) %>" class="poll_question_answer_video">
|
||||
<td><%= video.title %></td>
|
||||
<td><%= link_to video.url, video.url %></td>
|
||||
|
||||
@@ -5,5 +5,5 @@
|
||||
</h2>
|
||||
|
||||
<div class="poll-question-answer-video-form">
|
||||
<%= render "form", form_url: admin_answer_videos_path %>
|
||||
<%= render "form", form_url: admin_answer_videos_path(@answer) %>
|
||||
</div>
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace :admin do
|
||||
resources :answers, except: [:index, :show, :destroy], controller: "questions/answers", shallow: false
|
||||
resources :answers, only: [], controller: "questions/answers" do
|
||||
resources :images, controller: "questions/answers/images"
|
||||
resources :videos, controller: "questions/answers/videos"
|
||||
resources :videos, controller: "questions/answers/videos", shallow: false
|
||||
resources :documents, only: [:index, :create], controller: "questions/answers/documents"
|
||||
end
|
||||
post "/answers/order_answers", to: "questions/answers#order_answers"
|
||||
@@ -328,5 +328,5 @@ resolve "Poll::Question::Answer" do |answer, options|
|
||||
end
|
||||
|
||||
resolve "Poll::Question::Answer::Video" do |video, options|
|
||||
[:video, options.merge(id: video)]
|
||||
[:answer, :video, options.merge(answer_id: video.answer, id: video)]
|
||||
end
|
||||
|
||||
@@ -97,7 +97,7 @@ describe "Polymorphic routes" do
|
||||
it "routes poll answer videos" do
|
||||
video = create(:poll_answer_video)
|
||||
|
||||
expect(admin_polymorphic_path(video)).to eq admin_video_path(video)
|
||||
expect(admin_polymorphic_path(video)).to eq admin_answer_video_path(video.answer, video)
|
||||
end
|
||||
|
||||
it "routes milestones for resources with no hierarchy" do
|
||||
|
||||
@@ -26,7 +26,7 @@ describe "Videos", :admin do
|
||||
scenario "Update" do
|
||||
video = create(:poll_answer_video, answer: answer)
|
||||
|
||||
visit edit_admin_video_path(video)
|
||||
visit edit_admin_answer_video_path(answer, video)
|
||||
|
||||
fill_in "Title", with: title
|
||||
fill_in "External video", with: url
|
||||
|
||||
Reference in New Issue
Block a user