Add custom admin controller and use custom code inside controller

2,269 views
Skip to first unread message

Serega Sheypak

unread,
Jan 29, 2013, 4:04:33 AM1/29/13
to spree...@googlegroups.com
Hi!
I'm still in battle with spree. Looks cool but some concepts are not pack into my small brain.
My heroic target is to:
1. Make some custom code (spree-independent). I think I can put it into /lib and then pack as gem (I'm noob in ruby and rails :( )
2. Make custom admin controller with custom UI (simple UI forms usig exisitng taxonomy, prototype UI functionality) and use custom code

Whay did I do:
1. I did read guides. Unfortunately I'm rather dumb and it's not enough for me. i would be glad to share later with some receipts and acquired experience points, but right now I don't know where to start.

AndI have a question. Where do I have to put ## HOOKS FILE custom_spree_hooks.rb
It's not clear to me. The rest things in article are rather clear. Just reproduce it once and get an idea.

Please help me, I need some details. 

Nate Lowrie

unread,
Jan 29, 2013, 8:48:50 AM1/29/13
to spree...@googlegroups.com
My suggestion is to google making a gem for ruby.  With Bundler, it's super easy to install a gem from a git repo and there are plenty of tutorials out there.  If you want to make an extension for Spree, you can just do spree extension 'My-Extension' and it will create the base gem structure for you with the stubbed tie-ins for spree.  I would also take a look at existing extensions to see how to create the admin elements.  Generally, if you write an extension instead of the hooks you'll use Deface to add it.

For instance, in the spree_static_content gem, we add a tab to the admin menu by putting the following code in /app/ovverrides/static_content_admin_tab.rb

Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "static_content_admin_tab",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab(:pages, :icon => 'icon-file') %>",
                     :disabled => false)
Just make sure you have files ending with _override.rb set to automatically load...

Regards,

Nate

Serega Sheypak

unread,
Jan 29, 2013, 2:23:23 PM1/29/13
to spree...@googlegroups.com
Sorry, I didn't catch your idea.
I did suggest me to create a gem and do not do anyting iside spree app.
Ok, create a gem from git is not a rocket science :)

The snippet you provide raises an exception:

Showing /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/layouts/admin.html.erb where line #54 raised:

undefined method `admin_pages_path' for #<ActionDispatch::Routing::RoutesProxy:0x0000000636bb30>

Extracted source (around line #54):

51:           <div class="sixteen columns main-menu-wrapper">
52:             <ul data-hook="admin_tabs" class="inline-menu fullwidth-menu">
53: <%= render :partial => 'spree/admin/shared/tabs' %>
54:             <%= tab(:promotions, :url => spree.admin_promotions_path, :icon => 'icon-bullhorn') %><%= tab(:users, :url => spree.admin_users_path, :icon => 'icon-user') %><%= tab(:pages, :icon => 'icon-file') %>
55: </ul>
56: </div>
57:         </div>

:(
вторник, 29 января 2013 г., 13:04:33 UTC+4 пользователь Serega Sheypak написал:

Serega Sheypak

unread,
Jan 29, 2013, 2:38:39 PM1/29/13
to spree...@googlegroups.com
Sorry for early post.
1. I've created my custom contoller:
controllers/spree/admin/parser_controller.rb
class Spree::Admin::ParserController < ApplicationController
  def index
  end
end

2. I've added this snippet to routes.rb
Htdocs::Application.routes.draw do
 mount Spree::Core::Engine, :at => '/'
end

Spree::Core::Engine.routes.prepend do
  namespace :admin do
    resources :parser_controller
    end
end

3. I've created override admin_content_admin_tab_parser.rb
Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "admin_content_admin_tab_parser",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab :parser, :icon => 'icon-th-large' %>",
                     :disabled => false)

And I get mentioned exception. I don't understand what does it want from me more.

вторник, 29 января 2013 г., 23:23:23 UTC+4 пользователь Serega Sheypak написал:

Ryan Bigg

unread,
Jan 29, 2013, 3:51:04 PM1/29/13
to spree...@googlegroups.com
You need to call spree.admin_pages_path, not just admin_pages_path. Or at least, I think so...

Where is PagesController coming from and how are its routes defined?
--
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spree-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nate Lowrie

unread,
Jan 29, 2013, 5:02:15 PM1/29/13
to spree...@googlegroups.com
On Tuesday, January 29, 2013 3:51:04 PM UTC-5, Ryan Bigg wrote:
You need to call spree.admin_pages_path, not just admin_pages_path. Or at least, I think so...

Where is PagesController coming from and how are its routes defined?

Ryan,

That's not the issue.  The PagesController doesn't exist in his context.  It exists in spree_static_content which is where I pulled my original snippet from to show him how to do a deface override to add a tab for his controller.  He needed to change the symbol passed to match his controller.  I didn't make it clear what he needed to modify to make it work, hence the path error.
 
On 30/01/2013, at 6:38, Serega Sheypak <serega....@gmail.com> wrote:

Sorry for early post.
1. I've created my custom contoller:
controllers/spree/admin/parser_controller.rb
class Spree::Admin::ParserController < ApplicationController
  def index
  end
end

2. I've added this snippet to routes.rb
Htdocs::Application.routes.draw do
 mount Spree::Core::Engine, :at => '/'
end

Spree::Core::Engine.routes.prepend do
  namespace :admin do
    resources :parser_controller
    end
end

3. I've created override admin_content_admin_tab_parser.rb
Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "admin_content_admin_tab_parser",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab :parser, :icon => 'icon-th-large' %>",
                     :disabled => false)

And I get mentioned exception. I don't understand what does it want from me more.

Serega,

A few things.
  1. I am pretty sure that your controller needs to be pluralized.  It should be ParsersController located in file parsers_controller.rb.  
  2. ParsersController should inherit from Spree::Admin::ResourceController instead of ApplicationController.  This gives you access to the restful route helpers available.
  3. Your route for the ParsersController is wrong.  It needs to be
    namespace :admin do
        resources :parsers
      end
  4. Your Deface override is wrong.  You need to use the plural form.  Change the text variable to: "<%= tab :parsers %>"
  5. Once you fix #1-3, the routes error should go away.  If it does not, you can always manually specify the path by setting the Deface text to: "<%= tab :parsers, :url => spree.admin_parsers_path %>"
Regards,

Nate

Serega Sheypak

unread,
Feb 3, 2013, 3:10:27 PM2/3/13
to spree...@googlegroups.com
Sorry, my brain is blasted. It stopped to work again. I don't understand why. :(((


Error:

NoMethodError in Spree/admin/overview#index

Showing /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/layouts/admin.html.erb where line #54 raised:

undefined method `admin_parsers_path' for #<ActionDispatch::Routing::RoutesProxy:0x00000006ceba70>

Extracted source (around line #54):

51:           <div class="sixteen columns main-menu-wrapper">
52:             <ul data-hook="admin_tabs" class="inline-menu fullwidth-menu">
53: <%= render :partial => 'spree/admin/shared/tabs' %>
54:             <%= tab(:promotions, :url => spree.admin_promotions_path, :icon => 'icon-bullhorn') %><%= tab(:users, :url => spree.admin_users_path, :icon => 'icon-user') %><%= tab :parsers,  :icon => 'icon-th-large' %>

55: </ul>
56: </div>
57:         </div>


Controller:
module Spree
  module Admin
    class ParsersController < Spree::Admin::BaseController

      def index

      end

    end
  end
end

view:
<h1>Parser index.html</h1>

Deface:
Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "admin_content_admin_tab_parser",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab :parsers,  :icon => 'icon-th-large' %>",
                     :disabled => false)

вторник, 29 января 2013 г., 13:04:33 UTC+4 пользователь Serega Sheypak написал:
Hi!

Serega Sheypak

unread,
Feb 3, 2013, 3:19:05 PM2/3/13
to spree...@googlegroups.com
Your receipt gives the same error:

NoMethodError in Spree/admin/overview#index

Showing /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/layouts/admin.html.erb where line #54 raised:

undefined method `admin_parsers_path' for #<ActionDispatch::Routing::RoutesProxy:0x0000000612a560>

Extracted source (around line #54):

51:           <div class="sixteen columns main-menu-wrapper">
52:             <ul data-hook="admin_tabs" class="inline-menu fullwidth-menu">
53: <%= render :partial => 'spree/admin/shared/tabs' %>
54:             <%= tab(:promotions, :url => spree.admin_promotions_path, :icon => 'icon-bullhorn') %><%= tab(:users, :url => spree.admin_users_path, :icon => 'icon-user') %><%= tab :parsers,  :url => spree.admin_parsers_path, :icon => 'icon-th-large' %>
55: </ul>
56: </div> 
57: </div> 

in routes.rb:
Spree::Core::Engine.routes.prepend do
  namespace :admin do
    resources :parsers
  end
  end

Controller:
module Spree
  module Admin
    #class ParsersController < Spree::Admin::BaseController
    class ParsersController <  Spree::Admin::ResourceController
      def index

      end

    end
  end
end

Deface:
Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "admin_content_admin_tab_parser",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab :parsers,  :url => spree.admin_parsers_path, :icon => 'icon-th-large' %>",
                     :disabled => false)

Please help, I don't understand anything. Looks easy but completely unclear: where, what and how to do.

вторник, 29 января 2013 г., 13:04:33 UTC+4 пользователь Serega Sheypak написал:
Hi!

Nate Lowrie

unread,
Feb 4, 2013, 11:10:50 AM2/4/13
to spree...@googlegroups.com
What is the file name you put your ParsersController in?

Regards,

Nate

Serega Sheypak

unread,
Feb 4, 2013, 11:29:38 AM2/4/13
to spree...@googlegroups.com
app/controllers/spree/admin/parsers_controller.rb (using copy-paste from command line, pwd + ls-la)
module Spree
  module Admin
    #class ParsersController < Spree::Admin::BaseController
    class ParsersController <  Spree::Admin::ResourceController
      def index

      end

    end
  end
end

Deface::Override.new(:virtual_path => "spree/layouts/admin",
                     :name => "admin_content_admin_tab_parser",
                     :insert_bottom => "[data-hook='admin_tabs']",
                     :text => "<%= tab :parsers,  :url => spree.admin_parsers_path, :icon => 'icon-th-large' %>", #:url doesn't make sense
                     :disabled => false)


Htdocs::Application.routes.draw do
#
#Tons of default comments with explanations....
#
end

Do I have to put it inside Htdocs::Application.routes.draw do block?
Spree::Core::Engine.routes.prepend do
  namespace :admin do
    resources :parsers
    end
end

2013/2/4 Nate Lowrie <na...@finelineautomation.com>
What is the file name you put your ParsersController in?

Regards,

Nate

Ryan Bigg

unread,
Feb 4, 2013, 6:50:11 PM2/4/13
to spree...@googlegroups.com
If it's a Spree specific controller, it should be prepended to Spree::Core::Engine.routes. Do you have a basic application that you can share which reproduces this problem?

Serega Sheypak

unread,
Feb 5, 2013, 1:48:53 AM2/5/13
to spree...@googlegroups.com
Here it is... https://bitbucket.org/serega_sheypak/spree_1_3_1_custom/src

вторник, 5 февраля 2013 г., 3:50:11 UTC+4 пользователь Ryan Bigg написал:

Ryan Bigg

unread,
Feb 6, 2013, 5:08:51 PM2/6/13
to spree...@googlegroups.com
I am unable to reproduce this error on my local machine. I go to the admin area and I can see "Parsers". Did you fix this already?

Inline image 1
image.png

Serega Sheypak

unread,
Feb 7, 2013, 12:14:27 AM2/7/13
to spree...@googlegroups.com

No.... :((((((

07.02.2013 2:08 пользователь "Ryan Bigg" <ry...@spreecommerce.com> написал:
image.png

Ryan Bigg

unread,
Feb 7, 2013, 1:39:08 AM2/7/13
to spree...@googlegroups.com
Ok then. Do you have some steps to reproduce it? Maybe I am doing something wrong

 

On 07/02/2013, at 16:14, Serega Sheypak <serega....@gmail.com> wrote:

No.... :((((((

07.02.2013 2:08 пользователь "Ryan Bigg" <ry...@spreecommerce.com> написал:
I am unable to reproduce this error on my local machine. I go to the admin area and I can see "Parsers". Did you fix this already?

<image.png>

Serega Sheypak

unread,
Feb 7, 2013, 1:54:18 AM2/7/13
to spree...@googlegroups.com
I'm running it in development mode

Excuse me, i'm dump. It really works. But when I click "Parsers" tab, Ido get an exception:

NoMethodError in Spree::Admin::ParsersController#index

undefined method `key?' for nil:NilClass

Rails.root: /home/ssa/spree-1.3.1-0/apps/spree/htdocs

Application Trace | Framework Trace | Full Trace
actionpack (3.2.11) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.11) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.11) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.11) lib/abstract_controller/base.rb:115: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'
spree_core (1.3.1) lib/spree/core/middleware/redirect_legacy_product_url.rb:13:in `call'
spree_core (1.3.1) lib/spree/core/middleware/seo_assist.rb:27:in `call'
railties (3.2.11) lib/rails/engine.rb:479:in `call'
railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing'
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'
warden (1.1.1) lib/warden/manager.rb:35:in `block in call'
warden (1.1.1) lib/warden/manager.rb:34:in `catch'
warden (1.1.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.11) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25: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.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200: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__3361358607365163771__call__2874957534666765577__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.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) 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.1) 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'
railties (3.2.11) lib/rails/railtie/configurable.rb:30:in `method_missing'
passenger (3.9.1.beta) lib/phusion_passenger/rack/thread_handler_extension.rb:67:in `process_request'
passenger (3.9.1.beta) lib/phusion_passenger/request_handler/thread_handler.rb:126:in `accept_and_process_next_request'
passenger (3.9.1.beta) lib/phusion_passenger/request_handler/thread_handler.rb:100:in `block in main_loop'
passenger (3.9.1.beta) lib/phusion_passenger/utils/robust_interruption.rb:82:in `disable_interruptions'
passenger (3.9.1.beta) lib/phusion_passenger/request_handler/thread_handler.rb:98:in `main_loop'
passenger (3.9.1.beta) lib/phusion_passenger/request_handler.rb:432:in `block (3 levels) in start_threads'

Request

Parameters:

None

Show session dump

_csrf_token: "+Mj3yDAUaJzqIcXZSoC3rMauTNLWcdQ1s7jT2xiB7y8="
last_jirafe_sync: Thu, 07 Feb 2013 10:49:21 +0400
order_id: 1069267038
session_id: "eee603a5b68fa1da7cbbda65259e084c"
warden.user.user.key: ["Spree::User", [1], "Bkv5F3un6AxTfGXy9DQZ"]

Show env dump

HTTP_ACCEPT: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
HTTP_ACCEPT_CHARSET: "windows-1251,utf-8;q=0.7,*;q=0.3"
HTTP_ACCEPT_ENCODING: "gzip,deflate,sdch"
HTTP_ACCEPT_LANGUAGE: "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4"
REMOTE_ADDR: "127.0.0.1"
SERVER_NAME: "localhost"
SERVER_PROTOCOL: "HTTP/1.1"

Response

Headers:

None

I did expect to see <h1>Parser index.html</h1>
from views/spree/admin/parsers/index.html

What do I do wrong?

2013/2/7 Ryan Bigg <ry...@spreecommerce.com>

Ryan Bigg

unread,
Feb 7, 2013, 2:05:21 AM2/7/13
to spree...@googlegroups.com
Oh, that's the error. I didn't try clicking on parsers. I will check this again tomorrow. I thought the error as with the parsers link.

 

Serega Sheypak

unread,
Feb 10, 2013, 7:05:26 AM2/10/13
to spree...@googlegroups.com
Hi, are there anynew info? What can I try next :( Unfortunately, I cn't find a way to implement the simpliest things. ^(

четверг, 7 февраля 2013 г., 11:05:21 UTC+4 пользователь Ryan Bigg написал:

Serega Sheypak

unread,
Feb 10, 2013, 7:23:42 AM2/10/13
to spree...@googlegroups.com
yeah, I've fixed it.

module Spree
  class Parser < ActiveRecord::Base
    has_many    :parser_mappings,:dependent => :destroy
    #was: 
    #belongs_to  :taxon, :prototype 
    
#Correct version:    
    belongs_to  :taxon
    belongs_to  :prototype

    validates :parser_mapping_ids, :taxon_id, :prototype_id, :source_url, :title, :presence => true

    attr_accessible :parser_mapping_ids, :taxon_id, :prototype_id, :source_url, :title, :description

  end

end


вторник, 29 января 2013 г., 13:04:33 UTC+4 пользователь Serega Sheypak написал:
Hi!

Ryan Bigg

unread,
Feb 10, 2013, 3:05:34 PM2/10/13
to spree...@googlegroups.com
No new info yet. I will find time today to take a look.
2013/2/7 Ryan Bigg <ry...@spreecommerce.com>

Serega Sheypak

unread,
Feb 11, 2013, 2:36:46 PM2/11/13
to spree...@googlegroups.com
It has absolutely magic behaviour. I'm completely frustrated.
Here is a model code:
module Spree
  class Parser < ActiveRecord::Base
    has_many    :parser_mappings,:dependent => :destroy
    belongs_to  :taxon
    belongs_to  :prototype

    validates :parser_mapping_ids, :taxon_id, :prototype_id, :source_url, :title, :presence => true

    attr_accessible :parser_mapping_ids, :taxon_id, :prototype_id, :source_url, :title, :description

  end

end

Here is controller code:
module Spree
  module Admin
    #class ParsersController < Spree::Admin::BaseController
    class ParsersController <  Spree::Admin::ResourceController
      def index
        @parser = Spree::Parser.new
      end

    end
  end
end

And got exception:

Started HEAD "/spree" for 127.0.0.1 at 2013-02-11 23:28:06 +0400


Started HEAD "/spree" for 127.0.0.1 at 2013-02-11 23:28:06 +0400


Started GET "/spree/admin/parsers" for 127.0.0.1 at 2013-02-11 23:28:06 +0400
Processing by Spree::HomeController#index as HTML
[1;32mDeface: [0m 1 overrides found for 'spree/layouts/spree_application'
[1;32mDeface: [0m 'add_analytics_header' matched 1 times with 'head'
Processing by Spree::HomeController#index as HTML

LoadError (Expected /home/ssa/spree-1.3.1-0/apps/spree/htdocs/app/models/parser.rb to define Parser):
  app/controllers/spree/admin/parsers_controller.rb:4:in `<module:Admin>'
  app/controllers/spree/admin/parsers_controller.rb:2:in `<module:Spree>'
  app/controllers/spree/admin/parsers_controller.rb:1:in `<top (required)>'


  [1m [35mSpree::Taxonomy Load (0.3ms) [0m  SELECT `spree_taxonomies`.* FROM `spree_taxonomies` ORDER BY spree_taxonomies.position
[1;32mDeface: [0m 1 overrides found for 'spree/layouts/spree_application'
[1;32mDeface: [0m 'add_analytics_header' matched 1 times with 'head'
  [1m [35mSpree::Taxonomy Load (0.2ms) [0m  SELECT `spree_taxonomies`.* FROM `spree_taxonomies` ORDER BY spree_taxonomies.position
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.5ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (7.2ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (115.6ms)
  [1m [36mSpree::Taxon Load (0.3ms) [0m   [1mSELECT `spree_taxons`.* FROM `spree_taxons` WHERE `spree_taxons`.`parent_id` IS NULL AND `spree_taxons`.`taxonomy_id` IN (475199832, 854451430, 854451431, 854451432) [0m
  [1m [35mSpree::Taxon Load (0.3ms) [0m  SELECT `spree_taxons`.* FROM `spree_taxons` WHERE `spree_taxons`.`parent_id` IN (20000, 1000, 558398359, 558398362) ORDER BY lft
  [1m [36mEXPLAIN (0.2ms) [0m   [1mEXPLAIN SELECT `spree_taxonomies`.* FROM `spree_taxonomies` ORDER BY spree_taxonomies.position [0m
  [1m [35mEXPLAIN (0.2ms) [0m  EXPLAIN SELECT `spree_taxons`.* FROM `spree_taxons` WHERE `spree_taxons`.`parent_id` IS NULL AND `spree_taxons`.`taxonomy_id` IN (475199832, 854451430, 854451431, 854451432)
  [1m [36mEXPLAIN (0.1ms) [0m   [1mEXPLAIN SELECT `spree_taxons`.* FROM `spree_taxons` WHERE `spree_taxons`.`parent_id` IN (20000, 1000, 558398359, 558398362) ORDER BY lft [0m
EXPLAIN for: SELECT `spree_taxonomies`.* FROM `spree_taxonomies`  ORDER BY spree_taxonomies.position
+----+-------------+------------------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table            | type | possible_keys | key  | key_len | ref  | rows | Extra          |
+----+-------------+------------------+------+---------------+------+---------+------+------+----------------+
|  1 | SIMPLE      | spree_taxonomies | ALL  | NULL          | NULL | NULL    | NULL |    4 | Using filesort |
+----+-------------+------------------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)


WTF man??? Yesterday it was working!!!

Ok. Let's try some magic bro. Looks like something undescribable.
I did comment a line in controller:
#@parser = Spree::Parser.new

Let's try to refresh page and get expected exception:

  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.1ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (15.2ms)


Started GET "/spree/admin/parsers" for 127.0.0.1 at 2013-02-11 23:29:16 +0400

NoMethodError (undefined method `key?' for nil:NilClass):
  actionpack (3.2.11) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
  actionpack (3.2.11) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
  actionpack (3.2.11) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
  actionpack (3.2.11) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
  actionpack (3.2.11) lib/abstract_controller/base.rb:115:in `process'
  actionpack (3.2.11) lib/abstract_controller/rendering.rb:45:in `process'

Okay, no problem. My view code tries to pull some model methods from nil.
Again magic: uncomment a line of code and try to refresh page:
@parser = Spree::Parser.new

Wow, it works :))))

 Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.4ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.2ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.11/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (15.2ms)


Started GET "/spree/admin/parsers" for 127.0.0.1 at 2013-02-11 23:29:22 +0400
  [1m [36mSpree::Preference Load (0.3ms) [0m   [1mSELECT `spree_preferences`.* FROM `spree_preferences` WHERE (`spree_preferences`.`key` IS NOT NULL) AND (`spree_preferences`.`value_type` IS NOT NULL) [0m
Processing by Spree::Admin::ParsersController#index as HTML
  [1m [35mSpree::User Load (0.5ms) [0m  SELECT `spree_users`.* FROM `spree_users` WHERE `spree_users`.`id` = 1 LIMIT 1
  [1m [36m (0.6ms) [0m   [1mSELECT COUNT(*) FROM `spree_roles` INNER JOIN `spree_roles_users` ON `spree_roles`.`id` = `spree_roles_users`.`role_id` WHERE `spree_roles_users`.`user_id` = 1 AND `spree_roles`.`name` = 'admin' [0m
[1;32mDeface: [0m 4 overrides found for 'spree/layouts/admin'
[1;32mDeface: [0m 'promo_admin_tabs' matched 1 times with '[data-hook='admin_tabs'], #admin_tabs[data-hook]'
[1;32mDeface: [ERROR] [0m The original source for 'promo_admin_tabs' has changed, this override should be reviewed to ensure it's still valid.
[1;32mDeface: [0m 'auth_admin_login_navigation_bar' matched 1 times with '[data-hook='admin_login_navigation_bar'], #admin_login_navigation_bar[data-hook]'
[1;32mDeface: [ERROR] [0m The original source for 'auth_admin_login_navigation_bar' has changed, this override should be reviewed to ensure it's still valid.
[1;32mDeface: [0m 'user_admin_tabs' matched 1 times with '[data-hook='admin_tabs'], #admin_tabs[data-hook]'
[1;32mDeface: [WARNING] [0m No :original defined for 'user_admin_tabs', you should change its definition to include:
 :original => 'e49127029c733dcaf154ad0bd59102b63c57ac0b' 
[1;32mDeface: [0m 'admin_content_admin_tab_parser' matched 1 times with '[data-hook='admin_tabs']'
[1;32mDeface: [WARNING] [0m No :original defined for 'admin_content_admin_tab_parser', you should change its definition to include:
 :original => '6999548b86c700f2cc5d4f9d297c94b3617fd981' 
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/shared/_error_messages.html.erb (0.7ms)
  [1m [35mSpree::Prototype Load (0.4ms) [0m  SELECT `spree_prototypes`.* FROM `spree_prototypes` 
  [1m [36mSpree::Taxon Load (0.6ms) [0m   [1mSELECT `spree_taxons`.* FROM `spree_taxons` [0m
  Rendered spree/admin/parsers/index.html.erb within spree/layouts/admin (165.4ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/admin/shared/_translations.html.erb (3.3ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/admin/shared/_routes.html.erb (2.2ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/admin/shared/_head.html.erb (81.2ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/admin/shared/_alert.html.erb (0.0ms)
  Rendered /home/ssa/spree-1.3.1-0/ruby/lib/ruby/gems/1.9.1/gems/spree_core-1.3.1/app/views/spree/admin/shared/_tabs.html.erb (3.4ms)
Completed 200 OK in 460ms (Views: 292.7ms | ActiveRecord: 21.4ms)


Does these tricks have any explanation??? Looks like some cookie/cache problem... maybe I'm wrong.
Please help. I gonna kill myself. 

вторник, 29 января 2013 г., 13:04:33 UTC+4 пользователь Serega Sheypak написал:
Hi!

Ryan Bigg

unread,
Feb 11, 2013, 2:41:55 PM2/11/13
to spree...@googlegroups.com
Please don't kill yourself.


--

Serega Sheypak

unread,
Feb 11, 2013, 2:50:30 PM2/11/13
to spree...@googlegroups.com
I'll do my best to prevent it.

понедельник, 11 февраля 2013 г., 23:41:55 UTC+4 пользователь Ryan Bigg написал:

Ryan Bigg

unread,
Feb 12, 2013, 5:23:19 PM2/12/13
to spree...@googlegroups.com
The problem is caused by this line within your Parser model (which the console logs actually point to):

    belongs_to :taxon, :prototype

You must define different belongs_to associations on separate lines:

    belongs_to :taxon
    belongs_to :prototype

Serega Sheypak

unread,
Feb 13, 2013, 1:01:22 AM2/13/13
to spree...@googlegroups.com
I've already did it and it helped.
Then I turned off computer, started it next day and got mistary exception.
The model was ok at that time.
2013/2/13 Ryan Bigg <ry...@spreecommerce.com>
Reply all
Reply to author
Forward
0 new messages