开发者

Rails setting foreign_id for virtual attribute

开发者 https://www.devze.com 2023-02-19 04:16 出处:网络
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.

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消