【问题标题】:Ruby on Rails go to a specific page when clicking "f.submit"单击“f.submit”时,Ruby on Rails 会转到特定页面
【发布时间】:2015-02-23 10:13:01
【问题描述】:

在我的 Ruby on Rails 应用程序中,我有以下用于 booking_line 视图的表单:

<%= form_for @booking_line do |f| %>
    <%= f.hidden_field :showing_id %>
    <%= image_tag "thor_hammer.jpg",:size => "900x250" %>
    <td width="300px"> <br><%= f.label :seat_id, 'Please Select a Seat:' %>
    <br><%= f.collection_select :seat_id, free_seats, :id,:seats_available %><br>
    </td>
    <td width="300px">
    <div class="actions">
        <%= f.submit %>
    </div>
    <br>    
    <%= render "/error_messages", :message_header => "Cannot save: ", :target => @booking_line %> 
    </td>
<% end %>

但由于这是 booking_line,我想要发生的是,当单击提交按钮时,它会创建一个 booking_line 和一个 booking_line,因为在 booking_line 表中它具有属性 booking_id 以便在两者之间建立关联.我怎样才能做到这一点?

【问题讨论】:

  • 你定义了关系吗? booking_line 可以有多个 booking_line 还是只有一个 booking_line?
  • 请列出您的关联(针对 BookingLine、Booking 和 Seat)

标签: ruby-on-rails ruby forms associations form-submit


【解决方案1】:

您可以在form_for 方法中使用url 来覆盖个别约定,例如:

<%= form_for(@post, url: my_custom_path) do |f| %>
  ...
<% end %>

然后在my_custom action 处添加你自己的逻辑来实现它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-20
    • 1970-01-01
    • 2014-10-17
    • 2023-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多