Saving foreign key id's using form_for?

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 -%>