Non-model inputs

438 views
Skip to first unread message

Rainer Kuhn

unread,
Jun 13, 2012, 9:21:54 AM6/13/12
to plataformate...@googlegroups.com
Am I the only one who frequently tries to use simple_form for non-model forms or tries to add inputs to a form that don't belong to that model?

Why do I have to miss out on simple_form goodies for those?

Ray

Rafael Mendonça França

unread,
Jun 13, 2012, 9:23:03 AM6/13/12
to plataformate...@googlegroups.com
Can you provide an example of what you are trying to do?

Rainer Kuhn

unread,
Jun 13, 2012, 9:32:07 AM6/13/12
to plataformate...@googlegroups.com
Here you go. Views are absolutely not my strong suite, I feel much better deep in the backend.
CsvUpload has a mapping attribute, but not field_name or field_type

#columns
  = simple_form_for :csv_upload, url: wizard_path, method: :put do |f|
    - @columns.each_with_index do |column, i|
      div id="column_#{i.to_s}"
        = f.input :mapping, collection: @select_options, include_blank: false, selected: @mapping[i], :input_html => { name: "mapping[#{i}]" }, label: "Column #{i + 1} : #{column.humanize}"
        .new_custom_field
          = f.input :field_name, :input_html => { name: "field_name[#{i}]"}
          = f.input :field_type, collection: ["Text", "Date", "Number"], :input_html => { name: "field_type[#{i}]"}

    = f.submit "Import!"


On Wednesday, June 13, 2012 2:23:03 PM UTC+1, Rafael Mendonça França wrote:
Can you provide an example of what you are trying to do?

Rafael Mendonça França

unread,
Jun 13, 2012, 9:36:00 AM6/13/12
to plataformate...@googlegroups.com
SimpleForm, like the Rails Form Builder, only works with Active Model compilant objects. If the object is not Active Model compilant so you will have some troubles to get they working.

Rainer Kuhn

unread,
Jun 13, 2012, 10:01:44 AM6/13/12
to plataformate...@googlegroups.com
That's why I ask. Simple Form has a much better syntax. Especially for devs like me who only write forms if the frontend guys are too busy it would be awesome to handle all types of forms the same, easy way.

Rafael Mendonça França

unread,
Jun 13, 2012, 10:08:36 AM6/13/12
to plataformate...@googlegroups.com
Unfortunately we can't do nothing. The easier way to you work with this is making your object respect the Active Model API.

Rainer Kuhn

unread,
Jun 13, 2012, 10:11:52 AM6/13/12
to plataformate...@googlegroups.com
Which is probably the better way. Adding attribute accessors and the handling the logic in the model instead of the controller.

Carlos Antonio da Silva

unread,
Jun 13, 2012, 9:12:03 PM6/13/12
to plataformate...@googlegroups.com
I see you're trying to use a form with a "symbol" object, :csv_upload.

What's not working? Are you getting any error? As Rafael said, FormBuilders are supposed to receive an object to work with, but they should work with a :symbol as namespace, you would just not get *some* of the functionality, like automatic required fields that depend on validations.

-- 
At.
Carlos Antonio

Wil Moore

unread,
Jun 19, 2012, 4:27:35 PM6/19/12
to plataformate...@googlegroups.com
Which is probably the better way. Adding attribute accessors and the handling the logic in the model instead of the controller.

I wouldn't go that far...what are you supposed to do if you have service objects that are neither controllers nor entity/models?

 
Reply all
Reply to author
Forward
0 new messages