IP Address can't be blank in web form #69

Closed
tralston opened this Issue Mar 6, 2013 · 3 comments

Projects

None yet

2 participants

@tralston
tralston commented Mar 6, 2013

When I try to update my User model from rails console, it's easy, no errors. But if I use the standard edit web form that comes default with a new scaffolded model, I can't update anything if the IP address is blank. It's not a required field, so I don't enter data when I'm not testing it.

The error I get is:

Invalid Address
/opt/local/lib/ruby1.9/1.9.1/ipaddr.rb:543:in `in6_addr'
/opt/local/lib/ruby1.9/1.9.1/ipaddr.rb:481:in `initialize'
postgres_ext (0.2.0) lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb:95:in `new'
postgres_ext (0.2.0) lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb:95:in `string_to_cidr_address'
postgres_ext (0.2.0) lib/postgres_ext/active_record/connection_adapters/postgres_adapter.rb:46:in `type_cast_with_extended_types'
activerecord (3.2.11) lib/active_record/attribute_methods/dirty.rb:86:in `_field_changed?'
activerecord (3.2.11) lib/active_record/attribute_methods/dirty.rb:63:in `write_attribute'
activerecord (3.2.11) lib/active_record/attribute_methods/write.rb:14:in `last_ip='
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.11) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.11) lib/active_record/persistence.rb:216:in `block in update_attributes'
activerecord (3.2.11) lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
activerecord (3.2.11) lib/active_record/transactions.rb:208:in `transaction'
activerecord (3.2.11) lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
activerecord (3.2.11) lib/active_record/persistence.rb:215:in `update_attributes'
app/controllers/users_controller.rb:62:in `block in update'
actionpack (3.2.11) lib/action_controller/metal/mime_responds.rb:270:in `call'
actionpack (3.2.11) lib/action_controller/metal/mime_responds.rb:270:in `retrieve_collector_from_mimes'
actionpack (3.2.11) lib/action_controller/metal/mime_responds.rb:194:in `respond_to'
app/controllers/users_controller.rb:61:in `update'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.11) lib/active_support/callbacks.rb:414:in `_run__666161121132474432__process_action__1460296893390357955__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.11) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.11) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.11) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.11) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.11) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.11) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.11) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:36:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.11) lib/action_dispatch/routing/route_set.rb:601:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.11) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.11) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `_run__3619324192623174751__call__2595394282178501402__callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.11) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.11) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.11) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.11) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.11) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.11) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.11) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.11) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/opt/local/lib/ruby1.9/1.9.1/webrick/httpserver.rb:138:in `service'
/opt/local/lib/ruby1.9/1.9.1/webrick/httpserver.rb:94:in `run'
/opt/local/lib/ruby1.9/1.9.1/webrick/server.rb:191:in `block in start_thread'

I've tracked it down to the fact that an empty value in a web form field translates to an empty string: "".

In rails console, when I assign "nil" to the ip address, it works just fine. But when I assign an empty string with dbl-quotes, "", it has the same error. It seems like the "" needs to be transformed into a nil, at least when coming from a web form.

@danmcclain danmcclain added a commit that referenced this issue Mar 7, 2013
@danmcclain danmcclain Closes #69
Empty strings are converted to nil by string_to_cidr_address
3df1574
Contributor

Thanks for finding this, not sure how I missed it originally

@danmcclain danmcclain closed this Mar 7, 2013

Could you commit this to the master branch? That way I don't have to install my forked gem on every machine I want to include this in :)

@danmcclain danmcclain added a commit that referenced this issue Mar 23, 2013
@danmcclain danmcclain Closes #69
Empty strings are converted to nil by string_to_cidr_address
b2db0d3
Contributor

@tralston Should have been in master all along, accidentally had it in that branch, it's in master now, thanks for pointing that out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment