Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Colin Law
On 4 September 2015 at 15:32, Николай Спелый wrote: > There are no errors given. Instead rails puts result of Chat.find_by(id: > 6).chatusers, not result of "each", that's strange. Now I look again that is not surprising. The method inspect outputs to the server terminal

[Rails] Method each strange behavior with AR association

2015-09-04 Thread Николай Спелый
Hi. I write <%= Chat.find_by(id: 6).chatusers.each { |chat_user| chat_user.user.inspect } %> (There are three models: Chat, Chatuser, User) Chat.find_by(id: 6).chatusers returns collection of table "chats_users" and this is fine working. But i can not get model user by each element of

Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Colin Law
On 4 September 2015 at 14:46, Николай Спелый wrote: > Hi. > I write > <%= Chat.find_by(id: 6).chatusers.each { |chat_user| chat_user.user.inspect > } %> > > (There are three models: Chat, Chatuser, User) > > Chat.find_by(id: 6).chatusers returns collection of table

Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Николай Спелый
There are no errors given. Instead rails puts result of Chat.find_by(id: 6).chatusers, not result of "each", that's strange. class Chatuser < ActiveRecord::Base self.table_name = "chats_users" belongs_to :chat belongs_to :user validates :chat_id, presence: true validates :user_id,

Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Николай Спелый
Great ! I already try write this logic but it not works. But when i copy-paste your variant it's work. So difference is in formating code, i write in one line, you write in three lines. That's nice for resolving problem, but why it's works in divided style of ruby and not works in one-line

Re: [Rails] Method each strange behavior with AR association

2015-09-04 Thread Rob Biedenharn
> On 2015-Sep-4, at 15:56 , Николай Спелый wrote: > > Great ! > I already try write this logic but it not works. But when i copy-paste your > variant it's work. > So difference is in formating code, i write in one line, you write in three > lines. > That's nice for