RailsCasts Pro episodes are now free!

Learn more or hide this

Recent Comments

Avatar

In the comments a lot of answers on the topic of routers, I'll advise you the best site on this topic

Avatar

Thanks for sharing such, valuable information

Avatar

Thanks for the article, I was looking for information on this topic, helped a lot.

Avatar

It was very informative to watch, thanks for sharing. Keep up the good work.

Avatar

Where I am annoying to get to is existence able to chain a sequence of scopes, then smear pagination so I can output pages of alarms.

Avatar

Are you facing any kind of technical issues with your router device? don't worry, you can visit our site for help. our company provides solutions and services to the customers who are experiencing issues with their router device. they can visit our site and can interact with experts via support number which is also available on our website. so come to us and grab the best service in the market.

Avatar

Các loại bánh trung thu được đóng gói bằng các loại bao bì hết sức đẹp mắt và trang trọng , có thể làm quà để tặng cho người thân và gia đình trong dịp trung thu .

Avatar

yes you cn get more on [How hack roblox android]

Avatar

Very helpful advice in this particular post! It’s the little changes that make the largest changes. Thanks for sharing!

Avatar

Many thanks for sharing this very diverse opinion post where each expert has no doubt shared his best knowledge on the topic. Have more success in your journey.

Avatar

I am finding it hard to get this working. It looks to me as if my code is exactly the same apart from naming.

User model

ruby
  has_many :representative_groupings
  has_many :representatives, :through => :representative_groupings
  has_many :inverse_representative_groupings, :class_name => "RepresentativeGrouping", :foreign_key => "representative_user_id"
  has_many :represented, :through => :inverse_representative_groupings, :source => :user

representative grouping model

ruby
class RepresentativeGrouping < ApplicationRecord
  belongs_to :user
  belongs_to :representative, :class_name => "User"
end

I didnt use a migration to make this table as I already had it, i just renamed the name table name to suit

mysql> describe representative_groupings;
+------------------------+------------+------+-----+---------+----------------+
| Field                  | Type       | Null | Key | Default | Extra          |
+------------------------+------------+------+-----+---------+----------------+
| id                     | bigint(20) | NO   | PRI | NULL    | auto_increment |
| representative_user_id | bigint(20) | YES  | MUL | NULL    |                |
| user_id                | bigint(20) | YES  | MUL | NULL    |                |
| created_at             | datetime   | NO   |     | NULL    |                |
| updated_at             | datetime   | NO   |     | NULL    |                |
+------------------------+------------+------+-----+---------+----------------+

i test it with code like this:

ruby
    @u1 = User.create(:username => 'john1')
    @u2 = User.create(:username => 'mike1')
    rg = @u1.representative_groupings.build(:representative_user_id => @u2.id)
    rg.save

and try to view it like so:

ruby
<ul>
  <% for group in @u1.representative_groupings %>
    <li>
      <%= group.representative %>
    </li>
  <% end %>
</ul>

<br>

<ul>
  <% for user in @u2.represented %>
    <li><%= user %></li>
  <% end %>
</ul>

but i get this error:

ruby
ActionView::Template::Error (undefined method `username' for nil:NilClass):
    3: <ul>
    4:   <% for group in @u1.representative_groupings %>
    5:     <li>
    6:       <%= group.representative.username %>
    7:     </li>
    8:   <% end %>
    9: </ul>

if i just print out the 'group':

[#<RepresentativeGrouping id: 11, representative_user_id: 2, user_id: 1, created_at: "2017-08-16 13:51:59", updated_at: "2017-08-16 13:51:59">]

and i can access its values, but it fails when i try to access the 'representative'.

I feel that its probably pretty close and that ive messed up a naming convention somewhere. Can anyone spot where the issue is?

Avatar

Gmail is the best email services you can link your social network account with Gmail it provides the best security and it has much more features Gmail is widely used all over the world which gives an edge to Gmail. Gmail Customer Support Number

Avatar

Check and get complete details to dianabol in Canada

Avatar

Hmm I think we can use this method to create a perfect calculation module for our site. Maybe we can tweak the code a little to calculate a big purchase :) Thanks for sharing this for us.

Avatar

Coming to GTA San Andreas, this is the latest version of GTA Vice City. This action, adventures game is a famous launch from series of gangster games, released by Rock Star games.

Avatar

if you face any issue in your google chrome browser then you can visit us for the support number of the customer care team of chrome.

Avatar

This is very nice blog and informative.

Avatar

Its a pretty good technique !

Avatar

It's really sad that ther is no more new videos

Avatar

Very interesting! Thanks!