This is my scenario. I have an expense entry form,
each expense must have one category - classic foreign key example
Now I see that has_one with a non-existent category is not caught, I
think Rails creates the new category automagically. I had to add
custom validation to the expense model to catch that
Next what I would like is on the expense entry view/form,
- Allow the user to select a category from a drop down (easily done
via collection_select helper).
- Also allow him to add a new category if required. My initial idea
was for an editable dropdown, I couldn't find one for rails. Next I
tried adding a textbox and a link/button to trigger an action on the
The submit button set off the entire expense validation on a category
add click. The link approach was not able to pass in the description
of the new category to the controller action createCategory
<%= text_select 'category', 'description' =>
with @category defined in the controller.
If I am not coherent.. please ask questions & help me out.