Spree, Rails 3, and theming
Well, I've been trying to change the default theme of spree by following this tutorial
http://blog.endpoint.com/2010/01/rails-ecommerce-spree-hooks-tutorial.html
But the homepage doesn't change at all, well since the tutorial is meant for rails 2, I'm just wonderin开发者_如何学编程g what do I need to change from the tutorial to make it work with rails 3?
Simpler solution than using hooks is welcomed. Also while I'm at it, is there a way to undo the command you run in rails like maybe uninstalling an extension.
- The solution that worked for me was to create my own extension say 'site' with
rails g spree:extention site
then I've look at my gems path and just opened the whole spree-core gem in another editor project and copied over theapp/views/layouts/spree_application.html.erb
.
If your html is not that different (mine is quite different at http://daugpigiau.lt) from default spree shop you might be able to only use hooks and override some of the parts. Still the only way I've found to know hook names was to look inside those spree core gems and templates that were interesting for me. After you know what hooks are of interest to you you can do something like:
class PigiauHooks < Spree::ThemeSupport::HookListener
# custom hooks go here
insert_after :admin_inside_head, 'shared/admin/ckeditor_include'
insert_before :admin_product_form_meta, 'shared/admin/product_editor'
insert_before :admin_product_form_additional_fields, 'shared/admin/unavailable_on'
end
These are just my own partials for the places I wanted to change.
- Yes you can undo the extension generation part as any other generation you just need to run
rails destroy spree:extension your_extension_name
and it will revert all the operation that were performed during it's generation
I've strugled with the overriding part at first cause documentation on this one has a bit too much blank spaces for the first time user to grasp.
To change the default theme of Spree you need to generate your own extension and override the view files from spree_core-0.30.1/app/views
in it. However, there's a little bug in the current version of Spree that can make theming and extension creation really confusing. According to the docs, to create a new extension you should run the following command:
$ rails g spree:extension myext
And it should produce the following output:
create myext
create myext/db
create myext/public
create myext/LICENSE
create myext/Rakefile
create myext/README.md
create myext/.gitignore
create myext/myext.gemspec
create myext/lib/tasks/install.rake
create myext/app
create myext/app/controllers
create myext/app/helpers
create myext/app/models
create myext/app/views
create myext/spec
exist myext/lib
create myext/lib/myext_hooks.rb
create myext/lib/tasks/myext.rake
create myext/lib/myext.rb
create myext/spec/spec_helper.rb
gemfile myext
However, the output is:
create myext
create myext/config
create myext/db
create myext/public
create myext/LICENSE
create myext/Rakefile
create myext/README.md
Could not find ".gitignore" in any of your source paths. Your current source paths are:
The current workaround is to change the line
gem 'spree'
in your Gemfile to
gem 'spree', :git => "git://github.com/railsdog/spree.git", :tag => "v0.30.1"
then run bundle install
and rails g spree:extension myext
again. It will create all the files correctly and plug it into your Gemfile. Then you can override all the necessary files in myext/app/views
精彩评论