This question is about a different approach I'm trying to the one asked here:
Passing IDs through a new Form
I have a group#view page
, that is accessed by a Person
. In this page, the Person
can see the members of the group via methods I developed. The problem is that I need to create the model Honors
using the Id from the group
, the id from the person
accessing the page, and the id from a member
of this group
.
In my Honors controller I have:
def create
@person = Person.find(current_person)
@asked_groupmembership = @person.owned_group_memberships.find_all_by_status(true,:include => [:group, :member])
@asked_groupmembership.each do |agm|
@honor = Honor.create(:group => Group.find(params[:group_id]),
:person => Person.find(current_person), :honored => Person.find(agm.member.id))
end
if @honor.save
...
end
In my view I have a link that directs the person
to the form in order to create a new honor:
<% @asked_groupmembership.each do |agm| %>
<%= link_to "Create Honor", new_honor_path(:group_id => @group.id, :person => current_person.id,
:honored => agm.member.id) %>
But in my forms I can't get the ids and stuff
<% form_for(:honor, :url => honors_path(:group_id, :person,
:honored)) do |f| %>
The error I get is that I can't find Group without an Id.
Any ideas? Thanks.
##Edited2##
Changed my crontroller
def new
#@person = Person.find(params[:person])
#@honored = Person.find(params[:honored])
#@group = Group.find(params[:group_id])
@honor = Honor.new
end
def create
@person = Person.find(current_person)
@honor = Honor.create(:group => Group.find(params[:group_id]),
:person => Person.find(params[:person]),
:honored => Person.find(params[:honored]))
if @honor.save
...
end