I'm trying to prevent the page from showing unless a params[:userid]
is an integer.
I know the code is being called, because its not throwing errors, its not rendering, and I manually told it to render, then not render to check.
Here is what I'm using to try and do it:
render nothing: true unless params[:userid].is_a? Integer
And from reading up quickly on Rails, this should work, at least in theory I suppose. The route is setup properly because I checked it and had the page read back the :userid
. There are no errors being thrown from the console, but here is the read out when using /account/jonathan/settings
as the route:
Started GET "/" for 127.0.0.1 at 2015-09-28 23:04:24 -0400 ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations" Processing by PagesController#home as HTML Rendered pages/home.html.erb within layouts/application (1.1ms) Completed 200 OK in 124ms (Views: 117.6ms | ActiveRecord: 0.0ms)
Started GET "/" for 127.0.0.1 at 2015-09-28 23:04:31 -0400 Processing by PagesController#home as HTML Rendered pages/home.html.erb within layouts/application (0.0ms) Completed 200 OK in 15ms (Views: 14.9ms | ActiveRecord: 0.0ms)
Started GET "/account/jonathan/settings" for 127.0.0.1 at 2015-09-28 23:04:32 -0400 Processing by AccountController#settings as HTML Parameters: {"userid"=>"jonathan"} Rendered text template (0.0ms) Completed 200 OK in 1ms (Views: 0.8ms | ActiveRecord: 0.0ms)
Started GET "/account/jonathan/settings" for 127.0.0.1 at 2015-09-28 23:04:38 -0400 Processing by AccountController#settings as HTML Parameters: {"userid"=>"jonathan"} Rendered text template (0.0ms) Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
And when using /account/1/settings
as the route:
Started GET "/account/1/settings" for 127.0.0.1 at 2015-09-28 23:27:00 -0400 Processing by AccountController#settings as HTML Parameters: {"userid"=>"1"} Rendered text template (0.0ms) Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
Started GET "/account/1/settings" for 127.0.0.1 at 2015-09-28 23:27:00 -0400 Processing by AccountController#settings as HTML Parameters: {"userid"=>"1"} Rendered text template (0.0ms) Completed 200 OK in 1ms (Views: 0.2ms | ActiveRecord: 0.0ms)
I have tried using a route such as /account/1/settings
and /account/jon/settings
and neither show whats wrong.
{"userid"=>"jonathan"}
, the value is a String. So, what's the problem? – Todd A. Jacobs"1"
is a String, too. This whole question seems like an X/Y problem. What functional issue are you really trying to solve by having a condition render based onparams[:userid]
? – Todd A. Jacobsredirect_to :login if params[:userid].blank?
ensures that a userid is present. – Todd A. Jacobs