# Nested Resouces,not getting parent id(project\_id) from form

**URL:** <https://www.ruby-forum.com/t/nested-resouces-not-getting-parent-id-project-id-from-form/152112>\
**Category:** Rails\
**Created:** [October 30, 2008, 5:48am UTC](https://www.ruby-forum.com/t/nested-resouces-not-getting-parent-id-project-id-from-form/152112 "2008-10-30T05:48:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srijith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@srijith](https://www.ruby-forum.com/u/srijith)\
**Post date:** [October 30, 2008, 5:48am UTC](https://www.ruby-forum.com/t/nested-resouces-not-getting-parent-id-project-id-from-form/152112/1 "2008-10-30T05:48:20Z")

</div>

Hi  
i am using nested resources,here project having has many relation with  
defects.  
Main problem here is i am not getting project\_id from edit form.What’s a  
problem if any one knows please help.

edit.html.erb  
\<% form\_for(@defect,@project) do |f| %\>  
\<%=f.text\_field :name%\>  
\<%end%\>

routes.rb  
map.resources :projects,:has\_many=\>:defects  
map.resources :defects

defecs\_controller.rb  
before\_filter :get\_project  
private  
def get\_project  
@project = Project.find(params[:project\_id])  
end

def edit  
code for update defects  
end

Here problem is from edit form i am getting project id.

---

<div class="post-metadata">

**Author:** ![srijith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c77e96/32.png) [@srijith](https://www.ruby-forum.com/u/srijith)\
**Post date:** [October 30, 2008, 6:18am UTC](https://www.ruby-forum.com/t/nested-resouces-not-getting-parent-id-project-id-from-form/152112/2 "2008-10-30T06:18:15Z")

</div>

babu nair wrote:

> Hi  
> i am using nested resources,here project having has many relation with  
> defects.  
> Main problem here is i am not getting project\_id from edit form.What’s a  
> problem if any one knows please help.
> 
> edit.html.erb  
> \<% form\_for(@defect,@project) do |f| %\>

try this  
\<% form\_for(@project,@defect) do |f| %\>

> \<%=f.text\_field :name%\>  
> \<%end%\>
