Hi I have nested resources i.e. projects which have many tasks and a
task belongs to a project.

In my project show view I show project info i.e. title and description
and then list all the tasks associated with it.

I want to have a simple non-javascript form which allows a user to add a
new task.

e.g.

<!-- listing tasks is above this -->
<% form_for @project, :url => @project, :method => "PUT" do |form| %>
  <% fields_for @project.tasks.first do |task|%>
        <p>
          Task: <%= task.text_field :title %>
        </p>
  <% end %>
<p>
  <%= submit_tag "Add Task", :class => "submit" %>
</p>
<% end %>

In the controller i have this

def show
  @project = Project.find(params[:id])
  #create an empty task for the form
  @project.task.create
end

Problems -
Since ive created an empty task for @project, this shows up in my list
of tasks when it shouldnt. I know i could check all tasks in the view to
see if they are actually records with .new_record? but thats adding code
to the view and i feel there must be a much better solution to this?

I also dont like this <% fields_for @project.tasks.first do |task|%> as
the .first implies im dealing with many empty tasks waiting to be
created when in fact there will only be one - is there a better
workaroudn for this as well?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to