Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7848705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:17:51+00:00 2026-06-02T18:17:51+00:00

I have a rails 3.2 app for a budget planner. My model features a

  • 0

I have a rails 3.2 app for a budget planner.

My model features a user, a user has one budget, and each budget has many budget_items. When a user is created, a budget is created for them.

When the user accesses their budget, I insert a blank budget_item if they have none. However, what I would like to do is prepopulate each budget with a set of default budget items with estimated costs. This can be done either on creation of the budget, or if the user accesses a blank budget.

I would like as clean an implementation as possible, as I’m trying to do things the ‘right way’ in Rails (not quite there yet if you see any unusual code 🙂

My code can be seen here: https://github.com/michaelward82/WeddingPlanner

Well though out answers will be considered better than quick answers. I will give a reasonable amount of time before awarding a correct answer.


Edit:

I have succedded in achieving the creating of default records by changing my BudgetsController in the following manner:

class BudgetsController < ApplicationController
  def show
    if current_user
      @budget = current_user.budget
      if @budget.budget_items.empty?
        set_default_budget_items @budget
      end
    else
      redirect_to log_in_path
    end
  end

  def update
    @budget = current_user.budget
    if @budget.update_attributes(params[:budget])
      redirect_to budget_path, :flash => { :success => "Budget changes saved" }
    else
      redirect_to budget_path, :flash => { :error => "Budget changes were not saved" }
    end
  end

  private

  def set_default_budget_items(budget)
    default_budget_items = [
      { "description"=>"Insurance", "estimated_cost"=>"110", "actual_cost"=>"0", "position"=>"1"},
      { "description"=>"The Service", "estimated_cost"=>"520", "actual_cost"=>"0", "position"=>"2"},
      { "description"=>"Reception (venue, food & drinks)", "estimated_cost"=>"4000",  "actual_cost"=>"0", "position"=>"3"}
    ]

    default_budget_items.each {|b| @budget.budget_items.new(b) }
  end
end

Is this the best way? I’m happy to go with this, but if there is a cleaner way to organise this then I’d be happy to know. There are sgnificantly more default items than seen above, so I doubt my controller is the place for this data to live.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:17:53+00:00Added an answer on June 2, 2026 at 6:17 pm

    I think that you’re making a heavy controller and this should probably be moved to the model. You want to keep your controllers skinny where possible. There’s plenty of articles on this google ‘rails skinny controllers’.

    http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model

    I would use a callback (probably after_create), depending on what exactly you plan for the rest of the application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that is using Devise, with a User model, no
I have a rails app with devise for my user model. In my app
I have a Rails app with users, suggestions and searches. There is a many-to-many
I have a rails app that has picked up a bit of traction, but
I have rails app which has a list of users. I have different relations
I have a rails app where i have a Contact model and with an
We have a Rails app that has some pages that are available to all
I have a rails app that is working fine except for one thing. When
I have a rails app that has approx 30 matches in routes.rb match '/send-email'
I have the following code in my Rails app: <h2>Budget (optional)</h2> <select id=trip_currency name=trip[currency]>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.