Input with field not in database. Is that possible? #621

Closed
btrscott opened this Issue Jul 14, 2012 · 3 comments

Comments

Projects
None yet
2 participants
@btrscott

I'd like to make an input with a field name not in the database model but I get an undefined method error. Is this possible with some option I can't seem to find?

In the example below, neither t or t2 exists in the model. The rails helper text_field_tag works fine but the simple_form does not. I've tried adding an :as option to give it a hint but no good. I even tried f.input_field but that didn't work either.

= simple_form_for(@mymodel) do |f|
= f.error_notification

.form-inputs
= text_field_tag('t')
= f.input :t2

.form-actions
= f.button :submit, "Save"

I can build it using rails form helper tags but then I have to manually add the corresponding wrappers to be consistent with the rest of the simple form. Which then is not simple.

The intent of all this is to process the input fields first and then store something different into the model.

@btrscott

This comment has been minimized.

Show comment Hide comment
@btrscott

btrscott Jul 14, 2012

I've discovered I can create a transient field in the model using attr_accessor. I guess this is the way?

I've discovered I can create a transient field in the model using attr_accessor. I guess this is the way?

@carlosantoniodasilva

This comment has been minimized.

Show comment Hide comment
@carlosantoniodasilva

carlosantoniodasilva Jul 14, 2012

Collaborator

The model needs to respond to the attribute you're using, thus having an accessor or method there is required yeah.

Please use the mailing list for questions :)

Collaborator

carlosantoniodasilva commented Jul 14, 2012

The model needs to respond to the attribute you're using, thus having an accessor or method there is required yeah.

Please use the mailing list for questions :)

@btrscott

This comment has been minimized.

Show comment Hide comment
@btrscott

btrscott Jul 15, 2012

Sorry for posting in the wrong place. Joined the google group.

Thanks for the gentle slap.

Sorry for posting in the wrong place. Joined the google group.

Thanks for the gentle slap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment