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 6237589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:03:32+00:00 2026-05-24T11:03:32+00:00

I’m currently trying to make a form called countcash that allows users to input

  • 0

I’m currently trying to make a form called countcash that allows users to input the actual number of quarters, dimes, nickels, pennies, twenties, tens, fives, ones and then the monetary value of any other items in the cash box and then when they hit submit, I want to total those values and set the cashstart field of my current shift record.

The real issue is that I’m not sure what my form is supposed to look like and how the controller/model are supposed to be setup in this instance.

I have a shift_id saved in a session[:shift_id] variable and the shift with that id is the shift that I want to modify with the calculated cashstart.

What does the <%= form_for %> tag need to look like if I want to follow the MVC correctly and how do I set up the controller/model to update the database with the calculated value? And what should I be setting the route to? I can’t find anything like this on either stack overflow or other rails forums (Although you’d think that modifying a single attribute through multiple text fields would be pretty straight forward)

Just as a reference, this is the form I was using previously (To no avail)

app/views/countcash.html.erb

<%= form_for @shift do |f| %>   

<table>
  <tr>  
    <th>Coins</th>
    <th></th>
  </tr>

  <tr>
    <td>Quarters: </td>
    <td><%= f.text_field :quarters %><br /></td>
  </tr>

  <tr>
    <td>Dimes: </td>
    <td><%= f.text_field :dimes %><br /></td>
  </tr>

  <tr>
    <td>Nickels: </td>
    <td><%= f.text_field :nickels %><br /></td>
  </tr>

  <tr>
    <td>Pennies: </td>
    <td><%= f.text_field :pennies %><br /></td>
  </tr>

  <tr>
    <th>Bills</th>
    <th></th>
  </tr>

  <tr>
    <td>Twenties: </td>
    <td><%= f.text_field :twenties %><br /></td>
  </tr>

  <tr>
    <td>Tens: </td>
    <td><%= f.text_field :tens %><br /></td>
  </tr>

  <tr>
    <td>Fives: </td>
    <td><%= f.text_field :fives %><br /></td>
  </tr>

  <tr>
    <td>Ones: </td>
    <td><%= f.text_field :ones %><br /></td>
  </tr>

  <tr>
    <th>Other</th>
    <th></th>
  </tr>

  <tr>
    <td>Value (in $): </td>
    <td><%= f.text_field :others %><br /></td>
  </tr>


</table>

<div class="actions">
    <%= f.submit %>
</div>
<% end %>

And here’s my shifts_controller that doesn’t do anything at the moment, since I’m not sure how I need to go about updating the attribute after the submit button is clicked

def countcash
    @shift = Shift.find(session[:shift_id])

    redirect_to(login_path)
end
  • 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-05-24T11:03:33+00:00Added an answer on May 24, 2026 at 11:03 am

    I think you are almost there, presumably you have a named route which allows you to do this as your form declaration:

    <%= form_for @shift, :url => countcash_shift_path(@shift) do |f| %>
    

    If in doubt, run rake routes in your console to determine if such routes exist. If it doesn’t, perhaps you would want to explore RESTful routes, which should look something like this in your routes.rb:

    resources :shifts
    

    Inside the countcash action in your controller, it’s just a matter of doing this:

    @shift = Shift.find(session[:id])
    @shift.update_attributes(params[:shift]
    

    This should work assuming that you have you have set up RESTful routes for your shift resource. Also, I am assuming that your model/database is set up with quarters, dimes, etc as individual fields (otherwise you will require some more advanced than update_attributes).

    Since you are not having these individual fields in the database (as per your comment), you should not be putting as part of the model’s form. So instead of:

    <%= f.text_field :dimes %>
    

    You’d do something like:

    <%= text_field_tag :dimes, params[:dimes] %>
    

    And inside your controller, you can just access them like so:

    params[:dimes] + params[:quarters] # multiply as per currency logic
    

    If you want to get a little more fancy, what you could do is write methods that take in these values, so you still leave the form as your current state, but add methods that take in the values and do something with it like so (for all types of currency, not just dimes):

    def dimes=(value)
      @running_total += value
    end
    

    In your controller, do this instead:

    @shift.attributes = params[:shift]
    

    So what happens is that when you pass your model the hash of attributes, it will try to assign the values based on the symbol names. So the value of dimes in params will be passed in as if this was being called:

    @shift.dimes = params[:shift][:dimes]
    

    I think that should work for you, assuming that you use @running_total for something. You could use @amount or something if that’s what you already have as a model attribute.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported

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.