Search code examples
ruby-on-railsruby-on-rails-3simple-form

SimpleForm without for (non model form)


Is it possible to use Simple Form (by: Plataformatec) without a model?

https://github.com/plataformatec/simple_form


Solution

  • You can use :symbol as the first argument.

    <%= simple_form_for :user, url: users_path do |f| %>
      <%= f.input :name, as: :string %>
      ...
    <% end %>
    

    It will output something like this:

    <form novalidate="novalidate" class="simple_form user" action="/users" accept-charset="UTF-8" method="post">
      ...
      <div class="input string required user_name">
        <label class="string required" for="user_name">
          <abbr title="required">*</abbr> Name
        </label>
        <input class="string required" type="text" name="user[name]" id="user_name" />
      </div>
      ...
    </form>