Rails simple_form 两个模型
我开始将 simple_form 用于 Rails 应用程序,在转换一些表单时,我遇到了一个正在使用的有两个模型的表单,有点像嵌入式表单。这可以用 simple_form 实现吗?
<% simple_form_for :topic, :url => forum_topics_path do |t| %>
<%= t.input :name, :label => 'Topic' %></p>
<p>First Post:<br/></p>
Title: <%= text_field :post, :title %> <--- this is where i start having problems
Body: <%= text_area :post, :body %>
<%= t.submit 'Save' %>
谢谢
I'm starting to use simple_form for a rails application, and while converting some of my forms, I came across one that has two models that it is working with, sort of an embedded form. Is this possible with simple_form?
<% simple_form_for :topic, :url => forum_topics_path do |t| %>
<%= t.input :name, :label => 'Topic' %></p>
<p>First Post:<br/></p>
Title: <%= text_field :post, :title %> <--- this is where i start having problems
Body: <%= text_area :post, :body %>
<%= t.submit 'Save' %>
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
simple_fields_for
:注释
注意
<%= simple_form_for ...
和<%= simple_fields_for 中的
(Rails 3.x 中必需)=
符号删除了“标题:”和“正文:”文本。使用为输入生成的标签,并根据需要使用 CSS 设置其位置的样式。
添加了使用
input_html
的示例Use
simple_fields_for
:Notes
Note the
=
symbol in<%= simple_form_for ...
and<%= simple_fields_for
(required in Rails 3.x)Removed "Title:" and "Body:" text. Use the label generated for the inputs and style their location with CSS as needed.
Added example of using
input_html
我正在使用另一种方法,效果很好。 Ryan Bates (RailsCasts) 创建了一个 gem 来处理这个问题。
有关详细信息,请参阅 https://github.com/reu/simple_nested_form。
There's another approach that I'm using and it works great. Ryan Bates (RailsCasts) has created a gem to handle this.
See https://github.com/reu/simple_nested_form for the details.