mardi 5 juillet 2016

simple_form collection with if else

I search a solution for a simple_form,

I have a collection with multi-selector but my simple_form changes depending on the selection.

I think to do something like this:

<%= simple_form_for @customer do |f| %>
            <%= f.input :civility, priority: [ "Mr" ], collection: ["Mr", "Mrs", "Mr and Mrs", "compagny" ] %>
                <% if params[:Mr] == "Mr" %>
                  <%= f.input :name %>
                  <%= f.input :surname %>
                  <%= f.input :adress %>
                <% elsif params[:Mrs] == "Mrs" %>
                  <%= f.input :name %>
                  <%= f.input :surname %>
                  <%= f.input :adress %>
                <% elsif params[:Mr and Mrs] == "Mr and Mrs" %>
                  <%= f.input :name %>
                  <%= f.input :surname %>
                  <%= f.input :name2 %>
                  <%= f.input :surname2 %>
                  <%= f.input :adress %>
                <% else params[:compagny] == "Compagny" %>
                  <%= f.input :compagny_name %>
                  <%= f.input :adress %>
            <%= f.submit :submit %>
        <% end %>

in my db

create_table "customers", force: :cascade do |t| t.string "civility" t.string "name" t.string "surname" t.string "name2" t.string "surname2" t.string "compagny_name" t.string "adress" t.datetime "created_at", null: false t.datetime "updated_at", null: false end

Thanks.

Aucun commentaire:

Enregistrer un commentaire