Forum: Ruby on Rails Nested Resouces,not getting parent id(project_id) from form

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B07ecd50510d6e697c5d9ed99d438de1?d=identicon&s=25 Srijith nair (srijith)
on 2008-10-30 05:48
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.
C5c0e0499446b84fd3bcc61cf7862539?d=identicon&s=25 Thani Ararsu (thaniyarasu)
on 2008-10-30 06:18
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%>
This topic is locked and can not be replied to.