I'm a beginner in Rails working through the Hartl tutorial while trying to
work on my own project(s) at the same time.

One Project I'm trying to work on is a basic 'assembly' application because
it's what I do now full time.

Right now it's a pretty basic app with 3 Models

Ingredient
Bulk
RecipeItem

There is a has_many through relationship between Ingredient and Bulk
through RecipeItem

In the recipe_items table there is an additional attribute i'm calling
quantity - it must be greater than 0 and less than 1.

The validation question I have is this.

Is there an easy way to set up a validation on a Bulk object that requires
its related RecipeItem objects to add up to one...after all the recipeitem
objects are added?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/f16095c4-da9e-44bd-a094-f9539a99885c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colin Law at Apr 25, 2014 at 7:28 am

    On 24 April 2014 20:50, wrote:
    I'm a beginner in Rails working through the Hartl tutorial while trying to
    work on my own project(s) at the same time.

    One Project I'm trying to work on is a basic 'assembly' application because
    it's what I do now full time.

    Right now it's a pretty basic app with 3 Models

    Ingredient
    Bulk
    RecipeItem

    There is a has_many through relationship between Ingredient and Bulk through
    RecipeItem

    In the recipe_items table there is an additional attribute i'm calling
    quantity - it must be greater than 0 and less than 1.
    What is the data type of quantity in the database?

    Colin
    The validation question I have is this.

    Is there an easy way to set up a validation on a Bulk object that requires
    its related RecipeItem objects to add up to one...after all the recipeitem
    objects are added?

    --
    You received this message because you are subscribed to the Google Groups
    "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an
    email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit
    https://groups.google.com/d/msgid/rubyonrails-talk/f16095c4-da9e-44bd-a094-f9539a99885c%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLskAEqEB62TeNXLfZhXAt-TMeUC%2BLU9_yct%3D2hvZpED8A%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Johnelahr at Apr 25, 2014 at 6:29 pm
    I don't know the exact set up but it's a float - the sum either needs to
    add up to 1 or 100 depending on how i set up the recipes. The only reason
    I'm doing this is I need a beginner project to work on and this is
    something i know - and the blog idea keeps bogging down.

    After more thought - here's what ideally i think i would like to do.

    Create a New Bulk - when ready click a button or link that says 'enter
    recipe'.

    The new recipe page has an add ingredient button that by ajax adds another
    line to the 'recipe' div on the end - it draws ingredients (via ajax) from
    the ingredient database, there's an outer div that would sum all the
    ingredient quantities and not allow the submit button to work until it adds
    up to the right number.

    Does that seem like the way to go about it?

    (at this point - all ingredients would be in lbs)

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/3fe3df14-679b-4008-937c-98d22ab63f32%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Colin Law at Apr 25, 2014 at 9:10 pm

    On 25 April 2014 19:29, wrote:
    I don't know the exact set up but it's a float - the sum either needs to add
    up to 1 or 100 depending on how i set up the recipes. The only reason I'm
    doing this is I need a beginner project to work on and this is something i
    know - and the blog idea keeps bogging down.
    Please remember to quote the previous message. No-one reading this
    will know what you are talking about.

    If it is a float you cannot test for the total exactly equal to one.
    You can never rely on floats being exactly equal to anything, due to
    rounding errors.

    My advice is to finish working right through the tutorial before
    working on your own project.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuRbZ0goX4V9Y0CXRE7Wj4VEZiVAeAEgtVB%2BMHqB6%2BJkg%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedApr 25, '14 at 6:09a
activeApr 25, '14 at 9:10p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Johnelahr: 2 posts Colin Law: 2 posts

People

Translate

site design / logo © 2022 Grokbase