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)
@honor = Honor.create(:group => Group.find(params[:group_id]),
:person => Person.find(current_person), :honored => Person.find(current_person))
if @honor.save
...
end
The problem is in this :honored => Person.find(current_person)
, that is not getting the right ID and I don`t know how to get it.
In my view:
<% @asked_gr开发者_StackOverflowoupmembership.each do |agm| %>
<% form_for(:honor, :url => honors_path(:group_id => @group.id, :person => current_person.id,:honor => agm.member.id)) do |f| %>
Any help?
Thanks.
If you need 3 components to properly create an honor record, you need to pass them from the form. You seem to be doing that part correctly.
:group_id => @group.id
:person => current_person.id
:honor => agm.member.id
To create the record, access the passed variables.
Honor.create(:group => Group.find(params[:group_id]),
:person => Person.find(params[:person]),
:honored => Person.find(params[:honor]))
Understanding the above isn't the most efficient, but used for demonstrative purposes. You'd likely want to avoid redundant database hits, e.g. :person => current_person
rather than another query
精彩评论