Add budget/investments#json_data method
This commit is contained in:
@@ -4,10 +4,11 @@ module Budgets
|
|||||||
include CommentableActions
|
include CommentableActions
|
||||||
include FlagActions
|
include FlagActions
|
||||||
|
|
||||||
before_action :authenticate_user!, except: [:index, :show]
|
before_action :authenticate_user!, except: [:index, :show, :json_data]
|
||||||
|
|
||||||
load_and_authorize_resource :budget
|
load_and_authorize_resource :budget, except: :json_data
|
||||||
load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment"
|
load_and_authorize_resource :investment, through: :budget, class: "Budget::Investment",
|
||||||
|
except: :json_data
|
||||||
|
|
||||||
before_action -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
|
before_action -> { flash.now[:notice] = flash[:notice].html_safe if flash[:html_safe] && flash[:notice] }
|
||||||
before_action :load_ballot, only: [:index, :show]
|
before_action :load_ballot, only: [:index, :show]
|
||||||
@@ -16,6 +17,8 @@ module Budgets
|
|||||||
before_action :load_categories, only: [:index, :new, :create]
|
before_action :load_categories, only: [:index, :new, :create]
|
||||||
before_action :set_default_budget_filter, only: :index
|
before_action :set_default_budget_filter, only: :index
|
||||||
|
|
||||||
|
skip_authorization_check only: :json_data
|
||||||
|
|
||||||
feature_flag :budgets
|
feature_flag :budgets
|
||||||
|
|
||||||
has_orders %w{most_voted newest oldest}, only: :show
|
has_orders %w{most_voted newest oldest}, only: :show
|
||||||
@@ -79,6 +82,19 @@ module Budgets
|
|||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def json_data
|
||||||
|
investment = Budget::Investment.find(params[:id])
|
||||||
|
data = {
|
||||||
|
investment_id: investment.id,
|
||||||
|
investment_title: investment.title,
|
||||||
|
budget_id: investment.budget.id
|
||||||
|
}.to_json
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: data }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def resource_model
|
def resource_model
|
||||||
|
|||||||
@@ -17,3 +17,5 @@ scope '/participatory_budget' do
|
|||||||
post :vote, on: :member
|
post :vote, on: :member
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get 'investments/:id/json_data', to: :json_data, controller: 'budgets/investments'
|
||||||
|
|||||||
Reference in New Issue
Block a user