vendredi 17 mars 2017

Redirect to page with form fields filled

I have to models in my application:

class User < ActiveRecord::Base
  has_many :telephones
end

class Telephone < ActiveRecord::Base
  belongs_to :user
end

and in my form to user i have user's fields and link to new or edit telephones, something like this:

.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")

If I fill in the username and age field of the user and click in button New, my application redirect to Telephone form, and after create, redirect back to User form with telephone created, but the data of fields name and age are lost. Why i do this saving user data when click in button New and redirect user form filled after create telephone??

Aucun commentaire:

Enregistrer un commentaire