English 中文(简体)
Nest铁 Objects形式和
原标题:Nested Rails Objects Forms and haml

我现在举出属于其他应用模式的铁路模型,现在要提供电解表,以便分别更新相关物体的记录,这令人感到非常困惑。

下面是一类样本,用以分析我想要达到的目标:

     class Booking < ActiveRecord::Base` 
          belongs_to :user
          belongs_to :department
          belongs_to :invoice, :class_name => "Department"

     end
  `  

之后,还试图提供假装。 我不熟悉黑帮派,似乎很少有涉及该案的文件。

= form_for :booking, :url => booking_path(@booking), :html => { :method => :put } do |form|
  %ul
    - @booking.errors.full_messages.each do |msg|
      %li= msg

      = label :booking, :status
      = form.text_field :status

      - form.fields_for :user do |user_form| 

      = user_form.label :user, :fullname
      = user_form.text_field :fullname

      = form.submit "Update this booking"

感谢你们的答复。

最佳回答

羞耻是tation。 铁路助手的实际使用根本不改变。 当你在2个空位上下一条线时,有一项理解是,你的冷却部分载于上,而前一条线没有受到约束。 因此:

%ul#hello
  %li My List Item

为此:

<ul id= hello >
  <li>My List Item</li>
</ul>

本条也适用于<代码>do。 如果你有一条铁路,那么你需要像你那样,把助手的 block块 in起来。 Haml将自动添加<代码>end。 你们应该改变你们的标志,以便看上去。

= form_for :booking, :url => booking_path(@booking), :html => { :method => :put } do |form|
  %ul
    - @booking.errors.full_messages.each do |msg|
      -# This is looking good so far... correct indent inside this `do` block
      %li= msg

      -# I don t feel like we are in the error messages block anymore, but you were still indented here.  I ve removed the indentation to indicate that we are no longer in that block.

    -# This will work fine, but is there a reason you didn t use `form.label :status` here?
    = label :booking, :status
    = form.text_field :status

    -# I ve changed this to use `= form.` because I believe the other version (-) is deprecated
    = form.fields_for :user do |user_form|
      -# You didn t have this indented correctly.  To be part of the do block you need to indent it appropriately.  Fixed.
      = user_form.label :fullname
      = user_form.text_field :fullname

    -# This is no longer part of the `fields_for` call, so I have removed the indentation again to indicate that this is part of the outer section.
    = form.submit "Update this booking"

希望这将有助于: Haml可能首先感到宽松,但我发现这大有助于发展速度,我更容易阅读和书写。 大约一个星期,但我上了,现在我永远不会回头:p

问题回答

Im目前通过类似问题开展工作。

一、导 言

class Project < ActiveRecord::Base
  has_many :meetings
end

以及儿童类别......

class Meeting < ActiveRecord::Base
  belongs_to :project
end

我发现,创建新会议的形式要求“@project”和“@meeting”(新会议目标)出席......

= form_for [@project,@meeting] do |f|
  ...

现有会议的编辑形式只需要@meetings 反对......

= form_for @meeting do |f|
  ...

您可以采取部分形式(假设你重新利用铁路公约,将_form.html.haml用于您的形式),并且只是 。 html。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...