hidden_field outside of object

10 views
Skip to first unread message

fugee ohu

unread,
Jan 19, 2018, 11:35:46 AM1/19/18
to Ruby on Rails: Talk
I'm using form_for @object but i need to include in the form a value that's not a valid method for the object, but the controller needs the value How do I do that?

Walter Lee Davis

unread,
Jan 19, 2018, 12:09:38 PM1/19/18
to rubyonra...@googlegroups.com

> On Jan 19, 2018, at 11:35 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> I'm using form_for @object but i need to include in the form a value that's not a valid method for the object, but the controller needs the value How do I do that?

Where will this value come from (in the form)? Are you setting it using JavaScript or some other means? If you add attr_accessor :my_made_up_method_name to the model class, you can use the form builder macros to create a field for that attribute. You won't be able to set it to a value using Ruby (unless you use a callback to set it to some default value), but you can get the field to appear in the form that way.

Walter

>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/219238f6-f3ec-4170-95d5-3246d167db5b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

fugee ohu

unread,
Jan 19, 2018, 7:34:21 PM1/19/18
to Ruby on Rails: Talk


On Friday, January 19, 2018 at 12:09:38 PM UTC-5, Walter Lee Davis wrote:

> On Jan 19, 2018, at 11:35 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> I'm using form_for @object but i need to include in the form a value that's not a valid method for the object, but the controller needs the value How do I do that?

Where will this value come from (in the form)? Are you setting it using JavaScript or some other means? If you add attr_accessor :my_made_up_method_name to the model class, you can use the form builder macros to create a field for that attribute. You won't be able to set it to a value using Ruby (unless you use a callback to set it to some default value), but you can get the field to appear in the form that way.

Walter

>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegrankoups.com.
Thanks
Reply all
Reply to author
Forward
0 new messages