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


Reply
Join the discussion
Create an account Log in

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

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

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

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.