Building Form Based On an Association in Rails -


i new rails , having bit of problem simple page putting learning , hoping might have suggestions on fix or better approach.

essentially, have concept of scratch pad. each pad has_many tasks , has_many notes. in pad's show, want have 2 independent forms. 1 adding tasks , 1 adding notes. problem is, build forms so:

<%= form_for([@pad, @pad.tasks.build]) |f| %>     <%= f.text_field :text %> <%= f.submit %> <% end %> 

now, since i've called .build, when later call below code render tasks renders additional, empty record in list.

<ul>     <%= render @pad.tasks %> </ul> 

i thought using nested form, seems require me use padscontroller::update rather taskscontroller:create want to.

what appropriate approach in situation? being new rails (started yesterday), i'm afraid i'm missing obvious.

edit: added source github repository. said, learning project me. https://github.com/douglinley/scratchpad

if want new task without being added @pad.tasks collection, believe can @pad.tasks.new instead of @pad.tasks.build (which add collection).

for more on build vs new, check out build vs new in rails 3


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -