form_for and saving models

Greetings Ladies and Gents,

I am learning rails and am wondering about a best practice? Currently
I am trying to save specific tasks for a project. So tasks has a
belongs_to :project and project does has_many :tasks. Well when
creating a new task I need to store to project_id in the tasks table.

Currently I can set the @tasks.project_id = in the
TasksController create method or I can set the @task.project_id = in the TasksController new method and set a hidden_field
in the form_for for project_id for task.

Both ways seem unsexy, but its the best way I found. Is there a
better way? This is a nested resource also.

Current code:

<% form_for [:project, @task] do |form| -%>

        <legend>Project Info</legend>
        <% fields_for :project do |p| %>
            <%= p.text_field :name, :disabled => :true %>
        <% end %>

        <%= render :partial => 'form', :object => form %>
        <%= submit_tag 'Create' %>

<% end -%>


Assuming you use the hidden field, then in create, you can do

@project = Project.find(params[:project]
@project.tasks << Task.create(params[:task])

I believe this works, but it's air code. In any event, the spirit of it is to create the task scoped by the project it belongs to rather than manually setting the id.

Make sense?