I'm trying to pass a foreign_id to a virtual attribute. The foreign_id is in the page params. I tried to pass is in the controller, but that didn't work.
Here is how I set up the virtual attribute (same as Railscasts episode 167):
def issue_contents
@issue_contents || issues.map(&:content).join(', ')
end
开发者_StackOverflow private
def assign_issues
if @issue_contents
self.issues = @issue_contents.split(",").map do |content|
Issue.find_or_create_by_content(content)
end
end
end
And the form is very basic:
...
<%= f.label :issue_contents %><br />
<%= f.text_field :issue_contents %>
I'd really appreciate any help. Thanks!
精彩评论