Hi, everyone. Need help here. the basic relationship is that a user has many microposts and comments, a micropost has many comments. What I want to do is to show a commenter's name in the brower.
Here's the code: # pagesController.rb # the "feed" method is to retrun some reletive microposts @feed_items=current_user.feed.paginate(:page=>params[:page]) # home.html.erb <%= render :partial=>'shared/feed_item', :collection=>@feed_items %> # _feed_item.html.erb <% for comment in feed_item.comments %> <% comment.commenter.name %> # this line cause the error, but <% comment.commenter %> is ok! <% end %> there's an error " Error during failsafe response: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string)" rror during failsafe response: incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string) /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ backtrace_cleaner.rb:10:in `sub' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ backtrace_cleaner.rb:10:in `block in initialize' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:72:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:72:in `block (2 levels) in filter' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:72:in `map' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:72:in `block in filter' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:71:in `each' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:71:in `filter' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/backtrace_cleaner.rb:26:in `clean' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:150:in `clean_backtrace' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:137:in `application_trace' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:131:in `block in log_error' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/deprecation/reporting.rb:16:in `silence' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:128:in `log_error' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:64:in `render_exception' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/show_exceptions.rb:59:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ rack/logger.rb:13:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/ runtime.rb:17:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.5/lib/ active_support/cache/strategy/local_cache.rb:72:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/lock.rb: 11:in `block in call' <internal:prelude>:10:in `synchronize' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/lock.rb: 11:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/ action_dispatch/middleware/static.rb:30:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ application.rb:168:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ application.rb:77:in `method_missing' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/railties-3.0.5/lib/rails/ rack/log_tailer.rb:14:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/ content_length.rb:13:in `call' /usr/local/ruby/lib/ruby/gems/1.9.1/gems/rack-1.2.3/lib/rack/handler/ webrick.rb:52:in `service' /usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' /usr/local/ruby/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' /usr/local/ruby/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' so I placed this line in the home.html.erb to test <%= @feed_items.first.comments.first.commenter.name %> it's worked! I'm very confused. I mean what's the difference between these two ways? And also the error message, it's very strange. because I've specified utf-8 encoding in the database.yml -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.