All threads / Strong Parameters issue when upgarding Rails from 4.1.8 to 4.2.5

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Strong Parameters issue when upgarding Rails from 4.1.8 to 4.2.5

Parth Patel asked in Rails
I am new to rails and trying to understand what the issue is when the rails version is updated. Is this something related to strong_parameters? the way 
params[:budgets_updator][:budget])
is used in the controller. If so, how can I rewrite this using strong parameters?

Model:
class Budget < ActiveRecord::Base
  before_save :add_update_log
  before_save :set_default_value

  delegate_query :filter_sort_paginate, to: 'BudgetFetchQuery'

  belongs_to :book
  belongs_to :team
  belongs_to :deliverable
  validates_uniqueness_of :quarter_name, scope: :deliverable_id

  def self.fetch(params={})
    self.filter_sort_paginate(params)
  end

  def unfunded
    100 - funded
  end

  def uncommitted
    100 - committed
  end

end

Controller:
class BudgetsController < ApplicationController

def create
    @deliverable = Deliverable.find(params[:deliverable_id])
    @updator     = BudgetsUpdator.new(@deliverable)

        begin
      @updator.update_or_create!(params[:budgets_updator][:budget])
      html = render_to_string 'show', foramt: :html, layout: false
      render json: {html: html, status: "OK"}
    rescue
      html = render_to_string partial: 'edit'
      render json: {html: html, status: "NOT OK"}
    end
  end
end

Budgets Updator code:
class BudgetsUpdator
  include Rails.application.routes.url_helpers
  extend  ActiveModel::Naming
  include ActiveModel::Conversion
  include ActiveModel::Validations

  attr_reader :deliverable, :start_date, :end_date

  def update_or_create!(params={})
    params = params.map{|_, attrs| attrs}
    ActiveRecord::Base.transaction do
      params.each do |attrs|
        budget = budget_list.find_by_quarter_name(attrs["quarter_name"])
        budget.update_attributes!(attrs)
      end
    end
    @budget_list = deliverable.reload.budget_list
  end
end


Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.