Rails:脚手架自动做一对多的关系 [英] Rails: Scaffold to automatically do one-to-many relationship
问题描述
messages
,然后对这些消息 / code>(一个消息
- >许多注释
),我必须通过并改变一切。例如,我必须在注释
的新
视图 <%form_for(@comment)do | f | %GT;
至此
<%form_for([@ message,@comment])do | f | %GT;
然后更改Action以设置 @message
$ ...
这个目前不能用Scaffold自动完成,对不对?
解决方案这是真的,但是,这不是故事的结尾。 Scaffold至少有两种选择,它们都能很好地工作,并且自动选择类之间的关系(基于ActiveRecord关系指示器,如has_many)。其中一个替代方法是精简,另一个是
Not sure if I'm reading this right, but it seems like Scaffold will not do a one-to-many relationship in its entirety. For instance, if I create messages
with scaffold and then I want comments
on those messages
(one message
-> many comments
), I have to go through and change everything. For instance, I have to change this in the comment
's new
view
<% form_for(@comment) do |f| %>
to this
<% form_for([@message, @comment]) do |f| %>
and then change the Action to set up the @message
var... amongst other things.
This cannot currently be done automatically with Scaffold, right?
解决方案 This is true, but, it's not the end of the story. There are at least two alternatives to Scaffold that both work quite well and automatically pick up on relationships between classes (based on your ActiveRecord relationship indicators like has_many). One of these alternatives is Streamlined and the other is ActiveScaffold.
They're mainly helpful for entering in data that your system requires that is not user entered data. For example, I use them for administrative tasks on tables where there's no point in building a complete UI for CRUD when one of the scaffold alternatives will do the job just fine for a seldom used feature. You wouldn't want to use them for comments on messages though.
这篇关于Rails:脚手架自动做一对多的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!