Sha256: 32483e361879925c6f699801f96756e1f0ee523dc5d365b8f37467dd009e5f19

Contents?: true

Size: 750 Bytes

Versions: 9

Compression:

Stored size: 750 Bytes

Contents

module ActiveRecordSurveyApi
	module Concerns
		module Controllers
			module Nodes
				extend ActiveSupport::Concern

				def all_nodes
					@survey.nodes
				end

				def node_by_id(id)
					ActiveRecordSurvey::Node.find(id)
				end

				def new_node(params)
					ActiveRecordSurvey::Node.new(node_params)
				end

				def json_params
					ActionController::Parameters.new(JSON.parse(request.body.read))
				end

				def node_params
					json_params.require(:node).permit(:text, nodes: [])
				end

				included do
					before_filter :find_survey, :if => proc { |c| params[:survey_id].to_i > 0 }
				end

				def find_survey
					self.instance_variable_set "@survey", ActiveRecordSurvey::Survey.find(params[:survey_id])
				end
			end
		end
	end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
active_record_survey_api-0.0.19 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.18 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.17 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.14 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.12 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.11 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.7 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.6 lib/active_record_survey_api/concerns/controllers/nodes.rb
active_record_survey_api-0.0.4 lib/active_record_survey_api/concerns/controllers/nodes.rb