Rails Helpers

© 2012 - 2017 thoughtbot, inc. Upcase, the design of a robot, and thoughtbot are registered trademarks of thoughtbot, inc.


This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/intermediate-rails-5

Around 18:00 in the video, you use before_filter but I get an error in Rails 5, and some research on Stack Overflow seems to indicate that the before_filter syntax is deprecated in Rails 5.0, to be removed in 5.1. The new syntax is before_action.

1 Like

At 22:29 min in the video, I make that change and @user = User.find_by(username: params[:id]) but the error that i get undefined method shouts’ for nil:NilClasson the next line@shouts = @user.shouts` AnyIdea why? @bg-scro

If the username got a dot, the method to_param wouldn’t work correctly. For example, with a username ‘mr.anderson’, the parameters would be like this:
{"id"=>"mr", "format"=>"anderson"}
What rises an error, when I try to find it by ‘:id’ like this:
@user = User.find(username: params[:id])
becouse there is no user with username ‘mr’, there is a user with username ‘mr.anderson’.
Any ideas on how I could fix that?