gsubbing on a view/symbol

17 views
Skip to first unread message

Tom Allison

unread,
Sep 30, 2011, 8:57:59 AM9/30/11
to rubyonra...@googlegroups.com
I would love a full drop-in answer (hand me a fish), but I this might be a matter of pointing me to where I need to RTFM (teach me to fish).

I have a form with a text_area:

<%= f.text_area :modified_strategy, :options=>{:cols => 80} %>

the string represented by :modify_strategy is comprised of a pattern:
<many words>;<more words>;<maybe even more words>;

This string is a representation of what was originally three lines with "\n".
So to properly render them in a text_area I would want to do something like: gsub(";","\n")
and then reverse this in the Model before_save.

Unfortunately something as simple as

... :modifed_strategy.gsub(";", "\n") ...

returns an error:
undefined method `gsub' for :modified_strategy:Symbol

How do I change ";" to "\n" on the string represented by :modified_strategy?
Where to next because I guess I'm really missing something about Symbols or Views.

Tim Shaffer

unread,
Sep 30, 2011, 9:21:48 AM9/30/11
to rubyonra...@googlegroups.com
The :modified_strategy is just a symbol that tells the helper which method to call on your object to get the name/value of the textarea.

If you want to manually change the value of the textarea, you can overwrite the value attribute:

f.text_area(:modify_strategy , :value => f.object.modify_strategy.gsub(";", "\n"), :cols => 80)

Tom Allison

unread,
Sep 30, 2011, 11:47:13 AM9/30/11
to rubyonra...@googlegroups.com
wonderful.
still iffy on this Symbol concept but it seems I am not alone.  rtfm!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/GmpNEk0o4T4J.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply all
Reply to author
Forward
0 new messages