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
|
# GET /survey/questions/1.json
|
||||||
def create_from_template
|
def create_from_template
|
||||||
@template = Survey::Question.find(params[:id])
|
@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
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@@ -46,7 +48,8 @@ class Survey::QuestionsController < ApplicationController
|
|||||||
# GET /survey/questions/new.json
|
# GET /survey/questions/new.json
|
||||||
def new
|
def new
|
||||||
@survey_question = Survey::Question.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|
|
respond_to do |format|
|
||||||
format.html # new.html.erb
|
format.html # new.html.erb
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
module Survey::QuestionsHelper
|
module Survey::QuestionsHelper
|
||||||
def new_question_for(obj)
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,5 +16,6 @@ class Survey::Choice < ActiveRecord::Base
|
|||||||
def copy_from_template
|
def copy_from_template
|
||||||
cpy = Survey::Choice.new(self.attributes_for_copy)
|
cpy = Survey::Choice.new(self.attributes_for_copy)
|
||||||
cpy.save
|
cpy.save
|
||||||
|
cpy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
class Survey::Question < ActiveRecord::Base
|
class Survey::Question < ActiveRecord::Base
|
||||||
attr_accessible :text, :title, :typ, :choice_ids, :parent_type, :parent_id
|
attr_accessible :text, :title, :typ, :choice_ids, :parent_type, :parent_id
|
||||||
belongs_to :parent, polymorphic: true
|
belongs_to :parent, polymorphic: true
|
||||||
has_many :choices, dependent: :destroy
|
has_many :choices, dependent: :destroy, class_name: "Survey::Choice"
|
||||||
has_many :answers, through: :choices
|
has_many :answers, through: :choices
|
||||||
include IsCommentable
|
include IsCommentable
|
||||||
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
FLAG_ICONS={"delete" => "fa fa-trash", "template"=> "ffi1-cleaning1"}
|
||||||
@@ -20,6 +20,7 @@ class Survey::Question < ActiveRecord::Base
|
|||||||
self.choices.each do |c|
|
self.choices.each do |c|
|
||||||
cpy.choices << c.copy_from_template
|
cpy.choices << c.copy_from_template
|
||||||
end
|
end
|
||||||
|
cpy
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
<%= f.input :title %>
|
<%= f.input :title %>
|
||||||
<%= f.input :text %>
|
<%= f.input :text %>
|
||||||
|
|
||||||
|
<%= f.input :parent_type, as: :hidden %>
|
||||||
|
<%= f.input :parent_id, as: :hidden %>
|
||||||
|
|
||||||
<%= f.input :typ %>
|
<%= f.input :typ %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -1,3 +1,15 @@
|
|||||||
<% question_templates.each do |q| %>
|
<% 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 %>
|
<% 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) %>
|
<%= render_comments_for(@survey_question) %>
|
||||||
|
|
||||||
<%= link_to 'Edit', edit_survey_question_path(@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
|
get :answer
|
||||||
put :answer
|
put :answer
|
||||||
get 'flag'
|
get 'flag'
|
||||||
|
get :create_from_template
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :choices
|
resources :choices
|
||||||
|
|||||||
Reference in New Issue
Block a user