simple_form中的条件逻辑在Ruby中不起作用?

时间:2015-01-09 00:13:10

标签: ruby-on-rails ruby ruby-on-rails-4 simple-form

尝试在表单中包含条件逻辑。如果用户选择某种类型,则会显示与该类型相关联的信息。我怎样才能在表单中实现这一点?

<%= simple_form_for @post do |f| %>
        <%= f.input :title %>
        <%= f.input :image %>
        <%= f.input :description %>
        <%= f.input :link %>
        <%= f.collection_select :typeof, Post::TYPEOFS, :to_s, :humanize %>

        <% if @post.typeof.include?('audio') %>
            <p>Audio Selected</p>
            <% else %>
            <p>Something else selected</p>
            <% end %>

        <%= f.input :typeof %>
        <%= f.input :approve %>

        <%= f.button :submit, "Submit", class: "button" %>

    <% end %>

0 个答案:

没有答案