【发布时间】:2009-06-15 19:38:55
【问题描述】:
redirect_to :controller=>'groups',:action=>'invite'
但我收到错误,因为 redirect_to 发送 GET 方法我想将此方法更改为“POST”,redirect_to 中没有 :method 选项我该怎么办?没有redirect_to我可以这样做吗?
编辑:
我在 groups/invite.html.erb 中有这个
<%= link_to "Send invite", group_members_path(:group_member=>{:user_id=>friendship.friend.id, :group_id=>@group.id,:sender_id=>current_user.id,:status=>"requested"}), :method => :post %>
此链接在 group_members 控制器中调用创建操作,执行创建操作后,我想显示带有 group_id 的 groups/invite.html.erb(我的意思是单击“发送邀请”后将创建 group_members,然后当前页面将是显示)像这样:
redirect_to :controller=>'groups',:action=>'invite',:group_id=>@group_member.group_id
redirect_to 使用 GET 方法请求后,它会在组中调用 show action 并将邀请作为 id 并给出此错误
Couldn't find Group with ID=invite
我在群组中的邀请操作
def invite
@friendships = current_user.friendships.find(:all,:conditions=>"status='accepted'")
@requested_friendships=current_user.requested_friendships.find(:all,:conditions=>"status='accepted'")
@group=Group.find(params[:group_id])
end
解决方案是我必须使用 POST 方法重定向它,但我找不到方法。
丑陋的解决方案:我解决了这个我不喜欢的问题。如果您有公平的解决方案,我仍然会等待。
我的解决方案是为邀请添加路由以摆脱“找不到 ID=invite 的组”错误。
在 routes.rb 中
map.connect "/invite",:controller=>'groups',:action=>'invite'
在创建动作中
redirect_to "/invite?group_id=#{@group_member.group_id}"
我用英语“体力劳动者方法”(我认为)用五月语言“amele yontemi”将此解决方案称为。
【问题讨论】:
-
你为什么要这样?你能提供更多背景信息吗?
-
同意,我们需要更多关于您想要达到的目标的信息,然后才能真正给您一个好的答案。
标签: ruby-on-rails ruby