SimpleForm without for (non model form)

Edward Ford picture Edward Ford · Mar 3, 2011 · Viewed 55.6k times · Source

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

https://github.com/plataformatec/simple_form

Answer

htanata picture htanata · Mar 3, 2011

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>