Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中级作业中,这两段都有 “has_many… through:”的代码,但为什么syntax完全不一样? #78

Open
dyz2102 opened this issue Oct 24, 2016 · 1 comment

Comments

@dyz2102
Copy link

dyz2102 commented Oct 24, 2016

a.  【models/group.rb】 has_many :members, through: :group_relationships, source: :user
b.  【models/user.rb】  has_many :participated_groups, :through => :group_relationships, :source => :group
@dyz2102
Copy link
Author

dyz2102 commented Oct 24, 2016

【来自ray16897188】
a是b的一种简单写法,has_many也是rails的函数,它的一个参数是hash哈希类型,给这个类型的变量赋值的语法也可以参考Ruby的参考书。简单来说:
options = { :key1 => value1, :key2 => value2 }就是可以简写成:
options = { key1: value1, key2: value2 },与上面的正好对应

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant