I have a single text area input that I would like to get as a blob my new method on my controller, but would like to parse and otherwise mess with the input before it’s saved.
I know I can arbitrarily set attributes on a model by saying something like
@post.user_id = current_user.id
where that attribute isn’t coming directly from a form. My issue here though is that I want to set a nested model’s values.
Let’s say the association is post has_many comments and comment belongs_to post
Does post.comments just get set to a hash that looks like comments? Like
@post.comment = {'comment' => 'foo'}
Or something similar?
Thanks for any guidance on this.
if you have nested form fors, you can just get the comment values from your params via:
(you should have called @post.build_comment in your #new though)
If you’re looking to set them in your controller, then you need a hash ‘container’ for your comment like so:
or something like that