Is there any way to create a form with formtastic without a model?

前端 未结 1 1573
长情又很酷
长情又很酷 2021-02-04 04:11

I would like to use formtastic to create form but I don\'t have a model associated with that (login form with username, password and openid URL).

Of course I could creat

1条回答
  •  误落风尘
    2021-02-04 04:33

    You can pass a string instead of a model, which will be used to generate the field names:

    <% semantic_form_for 'user', :url => 'login' do |f| %>
        <% f.inputs :name => 'Login Details' do %>
            <%= f.input :username %>
            <%= f.input :password %>
        <% end %>
    <% end %>
    

    Which will produce something like:

    Login Details

    But you will need to be more specific with your options as formtastic won't be able to work out what types of fields it should use, all will default to textfields (although it automatically makes fields named like password password type fields).

    A better way to do this though would be with a sessions model, have a look at the way authlogic (http://github.com/binarylogic/authlogic) works for more info.

    0 讨论(0)
提交回复
热议问题