覆盖 ActiveScaffold 中的显示/编辑/等行为
我目前有一个由 ActiveScaffold 生成的通用列表。在列表中每行的末尾,ActiveScaffold 为每条记录添加标准 CRUD 链接 - 显示、编辑、删除。
我不想使用 ActiveScaffold 来执行这些操作(长话短说),并创建了我自己的控制器来处理这个问题。我试图覆盖这些链接以指向我自己的控制器,但我不太清楚如何传递记录的 ID。
例如,假设我希望 Show 的新链接为 /foo/show/[id] - 我的 ActiveScaffold 配置中有这样的内容:
config.show.link.action = "show"
config.show.link.parameters = {:controller => "foo", :id => ???}
我不知道要在 /foo/show/[id] 中传递什么>id 参数。我尝试过使用 :foo_id 或 foo_id 之类的东西,但控制器不知道它们是什么。例如,当我使用 :foo_id 时,我只得到字符串 - /foo/show/foo_id。
我的控制器在下面,但没有太多内容。
class MessagesController < ApplicationController
active_scaffold :messages do |config|
config.columns = [:eff_date, :exp_date, :type, :message]
config.show.link.action = "show"
config.show.link.parameters = {:controller => "show_messages", :id => ??}
end
end
我想继续在列表屏幕中使用 ActiveScaffold,因为我真的不想滚动我自己的列表版本。我发现有人在 googlegroups 中问了同样的问题,但没有回复。
http://www.mail-archive.com/[email protected]/msg00798.html
编辑:我应该添加不指定 :id 参数事实上将默认的 ActiveRecord ID 放入该字段中但这并不是我想要的 - 再说一遍,长话短说......:(
I currently have a generic list that is generated by ActiveScaffold. At the end of each row in the list, ActiveScaffold adds the standard CRUD links - Show, Edit, Delete - for each record.
I do not wish to use ActiveScaffold for these actions (long story) and have created my own controllers to handle this. I am trying to override these links to point to my own controllers but I can't quite work out how to pass through the ID of the record.
For example, say I want the new link for Show to be /foo/show/[id] - I have this in my ActiveScaffold configuration:
config.show.link.action = "show"
config.show.link.parameters = {:controller => "foo", :id => ???}
I don't know what to pass through in the id parameter. I have tried using things like :foo_id, or foo_id, but the controller doesn't know what they are. When I use :foo_id, for example, I just get the String - /foo/show/foo_id.
My controller is below, but there isn't much to it.
class MessagesController < ApplicationController
active_scaffold :messages do |config|
config.columns = [:eff_date, :exp_date, :type, :message]
config.show.link.action = "show"
config.show.link.parameters = {:controller => "show_messages", :id => ??}
end
end
I'd like to keep using ActiveScaffold for the list screen because I don't really want to have to roll my own version of the listing. I found a guy asking the same question in googlegroups but there was no response.
http://www.mail-archive.com/[email protected]/msg00798.html
Edit: I should add that not specifying the :id parameter does in fact put the default ActiveRecord ID in the field but it is not quite the one I want - again, long story ... :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这可能不是最好的解决方案,但它是最明显的。
在我的“编辑:”中,我添加了一个我最初省略的非常重要的细节。 ActiveScaffold 会自动将 URL 中的 ID 设置为当前记录中的 ID,但我的自定义控制器实际上需要不同的 ID(实际上是记录上的外键)。
解决方案 - 现在很明显 - 就是更改我的自定义控制器以使用它传递的默认 ID,并更改 ActiveRecord 查询以使用此 ID...d'oh。
Alright well this probably isn't the best solution but it's the most obvious.
In my "Edit:" I added in a pretty important detail that I originally omitted. ActiveScaffold was automatically setting the ID in the URL as one from the current record however my custom controllers actually required a different ID (a foreign key on the record, actually).
The solution - now obvious - was to just change my custom controller to use the default ID it passed through and change the ActiveRecord query to use this ID... d'oh.