gpt4 book ai didi

ruby-on-rails - ruby rails : What id do I want here?

转载 作者:数据小太阳 更新时间:2023-10-29 08:54:20 26 4
gpt4 key购买 nike

我在部分中有一个按钮,我想将其发送到我的 video_votes Controller 中的创建方法。该部分位于 video_votes View 目录中,但被呈现为位于视频 View 目录中的另一个部分。我的第一个问题是,我需要同时指定 Controller 和操作还是只指定操作?这是按钮:

<%= button_to "+1", { :action => "create", :id => @video.id, :type => "up" }, :remote => true %>

其次,我不确定应该将什么 ID 传递给按钮。 video模型有_many video_votes,video_votes属于video。

最佳答案

<%= button_to "+1", video_votes_path(@video, :type=> "up"), :remote => true %>

请记住,我不知道您的确切路线(我在 video_votes_path 上猜测),但在命令行中运行 rake routes 并将其设置为指向创建操作的路线在 video_votes Controller 中。可以传入video对象来表示id。

关于ruby-on-rails - ruby rails : What id do I want here?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5347797/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com