On 4 September 2015 at 15:32, Николай Спелый <peavey5150kh@gmail.com> 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 window not to the html for display, if you look
in the server window you should see it. You need to do something like
<% Chat.find_by(id: 6).chatusers.each do |chat_user| %>
<%= chat_user.user.name %>
<% end %>
If you are trying to get debug out then the best way is
<% logger.info Chat.find_by(id: 6).chatusers.each { |chat_user|
chat_user.user.inspect %>
which will appear in development.log. You can also use logger.info in
model or controller.
Colin
>
> class Chatuser < ActiveRecord::Base
> self.table_name = "chats_users"
> belongs_to :chat
> belongs_to :user
>
> validates :chat_id, presence: true
> validates :user_id, presence: true
> end
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/3ba9d885-0e29-4f76-995e-93c1b949f637%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtPvNnwA6VWYk6fytQq8mCjCD%2BQ0KETRv%2BaD256FtXaUQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment