Is it possible to use Simple Form (by: Plataformatec) without a model?
相关问题
- Question marks after images and js/css files in ra
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Is there a way to remove IDV Tags from an AIFF fil
- Rails how to handle error and exceptions in model
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
- Rspec controller error expecting <“index”> but
- Rspec controller error expecting <“index”> but
You can use
:symbol
as the first argument.It will output something like this:
All of the methods above still leave you with form data nested inside of "user" or whatever symbol that you pass as the first argument. That's annoying.
To mimic simple_form's style/benefits, but remove the object/symbol dependency and the forced data nesting, you can create a partial.
HAML
examples:form view:
field
partial:You can also use fields outside the model within a form model, with simple_fields_for like this:
This is simple and practical solution, because you can create different kind of fields from different models or without using models
You could also pass a
:symbol
instead of@object
as argument forsimple_form_for
.Which would output:
Please be aware of following draw-backs:
:url
and the type of eachinput
Unfortunately simple_form relies on using a model. Essentially it would be nice to have something like simple_form_tag and input_tag methods equivalent to their rails *_tag helpers. Until then, there's an easy work around.
Use a symbol instead of the class in the form and pass the value explicitly to prevent simple_form from trying to access the model properties.
This will avoid the
undefined method 'name' for User
error.