我有一个通过Person访问的group#view页面。在这个页面中,Person可以通过我开发的方法查看group的成员。问题是,我需要使用来自group的Id、来自访问页面的person的id以及来自此member的group的id来创建模型group。
在我的Honors控制器中,我有:
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问题出在这个:honored => Person.find(current_person)上,那就是没有获得正确的ID,我不知道如何获得它。
在我看来:
<% @asked_groupmembership.each do |agm| %>
<% form_for(:honor, :url => honors_path(:group_id => @group.id, :person => current_person.id,:honor => agm.member.id)) do |f| %>有什么帮助吗?
谢谢。
发布于 2011-05-24 22:58:45
如果您需要3个组件来正确创建荣誉记录,则需要从表单中传递它们。你看起来这部分做得很对。
:group_id => @group.id
:person => current_person.id
:honor => agm.member.id要创建记录,请访问传递的变量。
Honor.create(:group => Group.find(params[:group_id]),
:person => Person.find(params[:person]),
:honored => Person.find(params[:honor]))理解上面的内容并不是最有效的方法,但可以用于演示目的。您可能希望避免冗余的数据库命中,例如:person => current_person而不是另一个查询
https://stackoverflow.com/questions/6111419
复制相似问题