forked from bofh/fetsite
AutoCommit Fre Aug 7 01:03:02 CEST 2015
This commit is contained in:
@@ -31,7 +31,9 @@ class Survey::QuestionsController < ApplicationController
|
||||
# GET /survey/questions/1.json
|
||||
def create_from_template
|
||||
@template = Survey::Question.find(params[:id])
|
||||
|
||||
parent= params[:parent_type].constantize.find(params[:parent_id])
|
||||
@survey_question = @template.copy_from_template_for(parent)
|
||||
render action: :show
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -46,7 +48,8 @@ class Survey::QuestionsController < ApplicationController
|
||||
# GET /survey/questions/new.json
|
||||
def new
|
||||
@survey_question = Survey::Question.new
|
||||
@commentable=params[:commentable_type].constantize.find(params[:commentable_id])
|
||||
@parent=params[:parent_type].constantize.find(params[:parent_id])
|
||||
@survey_question.parent=@parent
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Survey::QuestionsHelper
|
||||
def new_question_for(obj)
|
||||
render partial: "survey/questions/new_question", locals: {question_templates: Survey::Question.templates}
|
||||
render partial: "survey/questions/new_question", locals: {question_templates: Survey::Question.templates, parent: obj}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -16,5 +16,6 @@ class Survey::Choice < ActiveRecord::Base
|
||||
def copy_from_template
|
||||
cpy = Survey::Choice.new(self.attributes_for_copy)
|
||||
cpy.save
|
||||
cpy
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
class Survey::Question < ActiveRecord::Base
|
||||
attr_accessible :text, :title, :typ, :choice_ids, :parent_type, :parent_id
|
||||
belongs_to :parent, polymorphic: true
|
||||
has_many :choices, dependent: :destroy
|
||||
has_many :choices, dependent: :destroy, class_name: "Survey::Choice"
|
||||
has_many :answers, through: :choices
|
||||
include IsCommentable
|
||||
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
||||
@@ -20,6 +20,7 @@ class Survey::Question < ActiveRecord::Base
|
||||
self.choices.each do |c|
|
||||
cpy.choices << c.copy_from_template
|
||||
end
|
||||
cpy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
<%= f.input :title %>
|
||||
<%= f.input :text %>
|
||||
|
||||
<%= f.input :parent_type, as: :hidden %>
|
||||
<%= f.input :parent_id, as: :hidden %>
|
||||
|
||||
<%= f.input :typ %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
<% question_templates.each do |q| %>
|
||||
<%= link_to q.title, new_survey_question_path() %>
|
||||
<%= link_to q.title, create_from_template_survey_question_path(q, params: {parent_type: parent.class.to_s, parent_id: parent.id.to_s}) %>
|
||||
<% end %>
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||
Neue Frage
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
||||
<li><%= link_to "Neue FRage", new_survey_question_path(params: {parent_type: parent.class.to_s, parent_id: parent.id.to_s}) %></li>
|
||||
<li><a href="#">Another action</a></li>
|
||||
<li><a href="#">Something else here</a></li>
|
||||
<li><a href="#">Separated link</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -9,4 +9,4 @@
|
||||
<%= render_comments_for(@survey_question) %>
|
||||
|
||||
<%= link_to 'Edit', edit_survey_question_path(@survey_question) %> |
|
||||
<%= link_to 'Back', survey_questions_path %>
|
||||
<%= link_to 'Back', polymorphic_path(@survey_question.parent) %>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
get :answer
|
||||
put :answer
|
||||
get 'flag'
|
||||
|
||||
get :create_from_template
|
||||
end
|
||||
end
|
||||
resources :choices
|
||||
|
||||
Reference in New Issue
Block a user