重定向到填写了表单字段的页面

时间:2017-03-17 13:16:20

标签: ruby-on-rails forms ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

我的应用程序中有两个模型:

class User < ActiveRecord::Base
  has_many :telephones
end

class Telephone < ActiveRecord::Base
  belongs_to :user
end

以我的形式发送给用户我有用户的字段并链接到新的或编辑电话,如下所示:

.panel.panel-default
  .panel-heading User
  .panel-body
    .row
      = f.input :name, wrapper_html: { class: "col-md-8" }
      = f.input :age, wrapper_html: { class: "col-md-4" }
    .row
      .col-md-4
        h4 Telefones
        - unless user.telephones.blank?
          table.table.table-borded
            thead
              tr
                th= Telephone.human_attribute_name(:title)
                th= Telephone.human_attribute_name(:number)
                th

            tbody
              - user.telephones.each do |telephone|
                tr
                  td= telephone.title
                  td= telephone.number
                td
                  = link_to(fa_icon("edit"), edit_telephone_path(telephone), class: "btn btn-sm btn-default") + " "
                  = link_to fa_icon("trash-o"), telephone_path(telephone), class: "btn btn-sm btn-danger",
                                                                              method: :delete,
                                                                              data: { confirm: t("titles.confirm") }
         = link_to(fa_icon("plus", text: "New"), new_telephone_path(), class: "btn btn-sm btn-success")

如果我填写用户的用户名和年龄字段并单击按钮New,我的应用程序重定向到电话表单,创建后,重定向回用户表单,创建电话,但字段名称和年龄的数据是丢失。 我这样做是什么时候点击按钮保存用户数据新建并重新定向用户表格后创建电话??

0 个答案:

没有答案
相关问题