Podio Rails Sample problems
First of all, thank you for your time. I'm not a veteran Ruby but I have a background in other non web development languages. I'm having problems with the Podio_rails_sample. Is it supposed to work out of the box completely after I fill in the client ID, secret, app id and space id? or am I supposed to fill in other information after that because i'm getting errors when I try to do anything except show tasks or delete. Those are the only two that "work out of the box." Below is my error received after clicking 'create a new lead'. I've also included my leadsController and leads.rb. Please help. I've been trying to correct this for months. Thank you for your time again. Organization Lead Contact Sales Contact Potential Revenue Probability Status Next follow up at Test Test Thomas Bilbrey USD3.00 57.000% 2015-05-13 Edit | Delete Create a new lead | Show tasks | Logout Here is the error I'm receiving... NoMethodError in LeadsController#new undefined method `[]' for nil:NilClass Extracted source (around line #25): 23 app = Podio::Application.find(APP_ID) 24 field = app.fields.find { |field| field['external_id'] == 'status' } 25 field['config']['settings']['allowed_values'] 26 end 27 28 def self.create_from_params(params) Rails.root: c:/Sites/podio_rails_sample Application Trace | Framework Trace | Full Trace app/models/lead.rb:25:in statuses' app/controllers/leads_controller.rb:37:inload_collections' activesupport (4.0.13) lib/active_support/callbacks.rb:397:in _run__451192218__process_action__callbacks' activesupport (4.0.13) lib/active_support/callbacks.rb:80:inrun_callbacks' actionpack (4.0.13) lib/abstract_controller/callbacks.rb:17:in process_action' actionpack (4.0.13) lib/action_controller/metal/rescue.rb:29:inprocess_action' actionpack (4.0.13) lib/action_controller/metal/instrumentation.rb:31:in block in process_action' activesupport (4.0.13) lib/active_support/notifications.rb:159:inblock in instrument' activesupport (4.0.13) lib/active_support/notifications/instrumenter.rb:20:in instrument' activesupport (4.0.13) lib/active_support/notifications.rb:159:ininstrument' actionpack (4.0.13) lib/action_controller/metal/instrumentation.rb:30:in process_action' actionpack (4.0.13) lib/action_controller/metal/params_wrapper.rb:250:inprocess_action' activerecord (4.0.13) lib/active_record/railties/controller_runtime.rb:18:in process_action' actionpack (4.0.13) lib/abstract_controller/base.rb:136:inprocess' actionpack (4.0.13) lib/abstract_controller/rendering.rb:44:in process' actionpack (4.0.13) lib/action_controller/metal.rb:195:indispatch' actionpack (4.0.13) lib/action_controller/metal/rack_delegation.rb:13:in dispatch' actionpack (4.0.13) lib/action_controller/metal.rb:231:inblock in action' actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:82:in call' actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:82:indispatch' actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:50:in call' actionpack (4.0.13) lib/action_dispatch/journey/router.rb:71:inblock in call' actionpack (4.0.13) lib/action_dispatch/journey/router.rb:59:in each' actionpack (4.0.13) lib/action_dispatch/journey/router.rb:59:incall' actionpack (4.0.13) lib/action_dispatch/routing/route_set.rb:676:in call' omniauth (1.2.2) lib/omniauth/strategy.rb:186:incall!' omniauth (1.2.2) lib/omniauth/strategy.rb:164:in call' omniauth (1.2.2) lib/omniauth/builder.rb:59:incall' rack (1.5.3) lib/rack/etag.rb:23:in call' rack (1.5.3) lib/rack/conditionalget.rb:25:incall' rack (1.5.3) lib/rack/head.rb:11:in call' actionpack (4.0.13) lib/action_dispatch/middleware/params_parser.rb:27:incall' actionpack (4.0.13) lib/action_dispatch/middleware/flash.rb:241:in call' rack (1.5.3) lib/rack/session/abstract/id.rb:225:incontext' rack (1.5.3) lib/rack/session/abstract/id.rb:220:in call' actionpack (4.0.13) lib/action_dispatch/middleware/cookies.rb:486:incall' activerecord (4.0.13) lib/active_record/query_cache.rb:36:in call' activerecord (4.0.13) lib/active_record/connection_adapters/abstract/connection_pool.rb:626:incall' actionpack (4.0.13) lib/action_dispatch/middleware/callbacks.rb:29:in block in call' activesupport (4.0.13) lib/active_support/callbacks.rb:373:inrun412837974call_callbacks' activesupport (4.0.13) lib/active_support/callbacks.rb:80:in run_callbacks' actionpack (4.0.13) lib/action_dispatch/middleware/callbacks.rb:27:incall' actionpack (4.0.13) lib/action_dispatch/middleware/reloader.rb:64:in call' actionpack (4.0.13) lib/action_dispatch/middleware/remote_ip.rb:76:incall' actionpack (4.0.13) lib/action_dispatch/middleware/debug_exceptions.rb:17:in call' actionpack (4.0.13) lib/action_dispatch/middleware/show_exceptions.rb:30:incall' railties (4.0.13) lib/rails/rack/logger.rb:38:in call_app' railties (4.0.13) lib/rails/rack/logger.rb:20:inblock in call' activesupport (4.0.13) lib/active_support/tagged_logging.rb:68:in block in tagged' activesupport (4.0.13) lib/active_support/tagged_logging.rb:26:intagged' activesupport (4.0.13) lib/active_support/tagged_logging.rb:68:in tagged' railties (4.0.13) lib/rails/rack/logger.rb:20:incall' actionpack (4.0.13) lib/action_dispatch/middleware/request_id.rb:21:in call' rack (1.5.3) lib/rack/methodoverride.rb:21:incall' rack (1.5.3) lib/rack/runtime.rb:17:in call' activesupport (4.0.13) lib/active_support/cache/strategy/local_cache.rb:83:incall' rack (1.5.3) lib/rack/lock.rb:17:in call' actionpack (4.0.13) lib/action_dispatch/middleware/static.rb:84:incall' rack (1.5.3) lib/rack/sendfile.rb:112:in call' railties (4.0.13) lib/rails/engine.rb:511:incall' railties (4.0.13) lib/rails/application.rb:97:in call' rack (1.5.3) lib/rack/lock.rb:17:incall' rack (1.5.3) lib/rack/content_length.rb:14:in call' rack (1.5.3) lib/rack/handler/webrick.rb:60:inservice' C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in service' C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:inrun' C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread' LeadsController class LeadsController < ApplicationController before_filter :load_collections, :only => [:new, :edit] def index @leads = Lead.all end def new @lead = Lead.new end def create Lead.create_from_params(params['lead']) redirect_to leads_path, :notice => 'Lead created' end def edit @lead = Lead.find_basic(params[:id]) end def update Lead.update_from_params(params[:id], params['lead']) redirect_to leads_path, :notice => 'Lead updated' end def destroy Lead.delete(params[:id]) redirect_to leads_path, :notice => 'Lead deleted' end #protected def load_collections @lead_contacts = Lead.space_contacts @sales_contacts = Lead.users @statuses = Lead.statuses end end lead.rb file class Lead < Podio::Item APP_ID = 12328033 SPACE_ID = 3204114 # Find all items in the Leads app def self.all collection = self.find_all(APP_ID) collection[:all] end # Find valid lead contacts in the space def self.space_contacts Podio::Contact.find_all_for_space(SPACE_ID, :order => 'contact', :limit => 12, :contact_type => 'space,connection', :exclude_self => false) rescue [] end # Find valid sales contacts in the space def self.users Podio::Contact.find_all_for_space(SPACE_ID, :order => 'contact', :limit => 12, :contact_type => 'user', :exclude_self => false) rescue [] end # Find valid statuses def self.statuses app = Podio::Application.find(APP_ID) field = app.fields.find { |field| field['external_id'] == 'status' } field['config']['settings']['allowed_values'] end def self.create_from_params(params) # raise fields.inspect self.create(APP_ID, { :fields => fields_from_params(params) }) end def self.update_from_params(id, params) self.update(id, { :fields => fields_from_params(params) }) end # # Map the field values return by the Podio API to simple getters # def organization field_values_by_external_id('company-or-organisation', :simple => true) end def lead_contact field_values_by_external_id('contacts', :simple => true).try(:[], 'name') end def sales_contact field_values_by_external_id('sales-contact', :simple => true).try(:[], 'name') end def potential_revenue_value field_values_by_external_id('potential-revenue').try(:first).try(:[], 'value').to_i end def potential_revenue_currency field_values_by_external_id('potential-revenue').try(:first).try(:[], 'currency') end def probability field_values_by_external_id('probability-of-sale', :simple => true) end def status field_values_by_external_id('status', :simple => true) end def followup_at field_values_by_external_id('next-follow-up').try(:first).try(:[], 'start').try(:to_datetime) end protected def field_values_by_external_id(external_id, options = {}) if self.fields.present? field = self.fields.find { |field| field['external_id'] == external_id } if field values = field['values'] if options[:simple] values.first['value'] else values end else nil end else nil end end def self.fields_from_params(params) { 'company-or-organisation' => params[:organization], 'contacts' => (params[:lead_contact].present? ? params[:lead_contact].to_i : nil), 'sales-contact' => (params[:sales_contact].present? ? params[:sales_contact].to_i : nil), 'potential-revenue' => { :value => params['potential_revenue_value'], :currency => params['potential_revenue_currency'] }, 'probability-of-sale' => params[:probability].to_i, 'status' => params[:status], 'next-follow-up' => DateTime.new(params['followup_at(1i)'].to_i, params['followup_at(2i)'].to_i, params['followup_at(3i)'].to_i).to_s(:db) }.delete_if { |k, v| v.nil? } end end

  • it's line 25 that's having trouble....field['config']['settings']['allowed_values'] NoMethodError in LeadsController#new undefined method `[]' for nil:NilClass Extracted source (around line #25): 23 app = Podio::Application.find(APP_ID) 24 field = app.fields.find { |field| field['external_id'] == 'status' } 25 field['config']['settings']['allowed_values'] 26 end 27 28 def self.create_from_params(params) Rails.root: c:/Sites/podio_rails_sample
This question is closed.