Solidus / Spree Override not working - ruby-on-rails

I'm trying to change the homepage product listing.
So i'm trying to override the file in this path:
https://github.com/solidusio/solidus/blob/master/frontend/app/views/spree/shared/_products.html.erb
Deface::Override.new(:virtual_path => 'spree/shared/products',
:replace_contents => "li#product_",
:name => "product_new",
:text => "text")
However this code makes absolutely 0 change on the homepage.
The file in which this override is in is called product_override.rb and is in app/overrides
Any help would be appreciated.
Thanks

I have tested this code with a fresh install of Solidus and it worked.
Note that I have added an underscore before "products" in :virtual_path => 'spree/shared/_products'. Also, I changed the selector to "li".
Deface::Override.new(:virtual_path => 'spree/shared/_products',
:insert_after => "li",
:name => "product_new",
:text => "Override is working")

Related

How to distinguish between Rails and Rake at the initializers level?

Whether I execute rails or rake, the code present in the initializers folder will be executed. What I want to do is to make sure that the code in a given initializer file doesn't get fired up when running a rake task (hence only when Rails server or console are launched).
For example, I'd like to be able to do something like (in config/initializers/blabla.rb):
do_something # code always executed
unless ENV['rake']
something_when_not_rake # code executed only if rails server or console
end
do_something_more # more code always executed
I've been looking into the ENV variable to see what's available there but I've seen nothing interesting, here's the content (in the format "key" => "value"):
"rvm_bin_path" => "/Users/lucke84/.rvm/bin"
"GEM_HOME" => "/Users/lucke84/.rvm/gems/ruby-2.2.3"
"SHELL" => "/bin/bash"
"TERM" => "xterm-256color"
"TMPDIR" => "/var/folders/73/q8t0jjrx3zb8zvd072dgq11c0000gn/T/"
"IRBRC" => "/Users/lucke84/.rvm/rubies/ruby-2.2.3/.irbrc"
"Apple_PubSub_Socket_Render" => "/private/tmp/com.apple.launchd.mF5Uh4NPbk/Render"
"MY_RUBY_HOME" => "/Users/lucke84/.rvm/rubies/ruby-2.2.3"
"USER" => "lucke84"
"rvm_stored_umask" => "0022"
"_system_type" => "Darwin"
"rvm_path" => "/Users/lucke84/.rvm"
"SSH_AUTH_SOCK" => "/private/tmp/com.apple.launchd.ryhqrdVtVU/Listeners"
"__CF_USER_TEXT_ENCODING" => "0x1F5:0x0:0x0"
"rvm_prefix" => "/Users/lucke84"
"PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/bin:/Users/lucke84/.rvm/gems/ruby-2.2.3#global/bin:/Users/lucke84/.rvm/rubies/ruby-2.2.3/bin:/Users/lucke84/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/apache-maven/apache-maven-3.3.1/bin"
"rvm_loaded_flag" => "1"
"PWD" => "/Users/lucke84/projects/website"
"JAVA_HOME" => "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"
"XPC_FLAGS" => "0x0"
"_system_arch" => "x86_64"
"_system_version" => "10.11"
"XPC_SERVICE_NAME" => "0"
"rvm_version" => "1.26.11 (latest)"
"HOME" => "/Users/lucke84"
"SHLVL" => "1"
"rvm_ruby_string" => "ruby-2.2.3"
"LOGNAME" => "lucke84"
"LC_CTYPE" => "en_US.UTF-8"
"GEM_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3:/Users/lucke84/.rvm/gems/ruby-2.2.3#global"
"rvm_delete_flag" => "0"
"RUBY_VERSION" => "ruby-2.2.3"
"_system_name" => "OSX"
"rvm_user_install_flag" => "1"
"BUNDLE_GEMFILE" => "/Users/lucke84/projects/website/Gemfile"
"_ORIGINAL_GEM_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3:/Users/lucke84/.rvm/gems/ruby-2.2.3#global"
"BUNDLE_BIN_PATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/bundler-1.10.6/bin/bundle"
"RUBYOPT" => "-rbundler/setup"
"RUBYLIB" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/bundler-1.10.6/lib"
"MANPATH" => "/Users/lucke84/.rvm/gems/ruby-2.2.3/gems/unicorn-5.0.1/man"
I cannot find a built-in environment key/value to programmatically determine who is triggering the command. Maybe one of you can shed some light on this topic for me?
Further details:
this cannot be an environment-dependent check, it should work for development as well as for production (or whatever the environment)
I would like to avoid to specify a custom parameter (i.e. bin/rake my:task skip_initializer=true), as what I'm trying to do is to skip that initializer's executions for all rake tasks
running Rails 4.2.x at the moment
Thanks in advance for your help!

How to implement badgeville in ruby on rails

Can anyone tell me how to implement badgeville in ruby on rails?
EDIT:
how can I apply this on ruby on rails?
https://github.com/badgeville/badgeville-ruby
I'm not sure how this particular gem work, but normally it should work with following steps
create a file called 'badgeville.rb' inside app/config/initializers
add the following code to badgeville.rb
BadgevilleBerlin::Config.conf(
:host_name => "http://example.com",
:api_key => MY_API_KEY)
restart
then you should be able to use the following commands inside your
controllers/ models
Ex:
new_site = BadgevilleBerlin::Site.new(
:name => "My Website",
:url => "mydomain.com",
:network_id => MY_NETWORK_ID )
success = new_site.save

Ruby add_item for eBay

I am attempting to write a ruby on rails app that posts an item to eBay. Cody Fauser/Garry Tan have a gem called ebayApi which is built on top of the ebay gem. When I attempt to post an item, I am getting an error back from ebay that says the condition ID is required for this category. I have found a category that does not require the condition, and I can post to that category. Searching through the eBay API documentation, I have found a tag conditionID under the "item" class. However, in the documentation for ebayAPI, there is no such tag. Looking back at the ebay API documentation, there is an older way to specify condition, using lookup_attributes. I have noted that the return xml is coming in API version 745, and Garry Gan's updated of the ruby interface is running version 609. I have tried using the lookup, and seem to get the same error (condition required). I am using the following code to specify the item:
#ebay = Ebay::Api.new :auth_token => #seller.ebay_token
item = Ebay::Types::Item.new( :primary_category => Ebay::Types::Category.new(:category_id => #ebayTemplate.categoryID),
:title => #ebayTemplate.name,
:description => #ebayTemplate.description,
:location => #ebayTemplate.location,
:start_price => Money.new((#ebayTemplate.startPrice*100).to_d, #ebayTemplate.currency),
:quantity => 1,
:listing_duration => #ebayTemplate.listingDuration,
:country => #ebayTemplate.country,
:currency => #ebayTemplate.currency,
:payment_methods => ['VisaMC', 'PayPal'],
:paypal_email_address => '********#gmail.com',
:dispatch_time_max => 3,
:lookup_attributes => [Ebay::Types::LookupAttribute.new( :name => "Condition", :value => "New")],
# :attribute_sets => [
# Ebay::Types::AttributeSet.new(
# :attribute_set_id => 2919,
# :attributes => [
# Ebay::Types::Attribute.new(
# :attribute_id => 10244,
# :values => [ Ebay::Types::Val.new(:value_id => 10425) ]
# )
# ]
# )
# ],
:shipping_details => Ebay::Types::ShippingDetails.new(
:shipping_service_options => [
# ShippingServiceOptions.new(
# :shipping_service_priority => 2, # Display priority in the listing
# :shipping_service => 'UPSNextDay',
# :shipping_service_cost => Money.new(1000, 'USD'),
# :shipping_surcharge => Money.new(299, 'USD')
# ),
Ebay::Types::ShippingServiceOptions.new(
:shipping_service_priority => 1, # Display priority in the listing
:shipping_service => #ebayTemplate.shipSvc,
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_surcharge => Money.new((#ebayTemplate.shipSurcharge*100).to_d, #ebayTemplate.currency)
)
],
:international_shipping_service_options => [
Ebay::Types::InternationalShippingServiceOptions.new(
:shipping_service => 'USPSPriorityMailInternational',
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_service_priority => 2,
:ship_to_location => #ebayTemplate.shipToLocation
)
]
),
:return_policy => Ebay::Types::ReturnPolicy.new (
:description => 'this product for suckers only!',
:returns_accepted_option => 'ReturnsAccepted'
)
#:condition_id => 1000
)
#response = #ebay.add_item(:item => item)
As you can see, it is just a mutation of the example given by Cody Fauser. The condition_id at the bottom will bring up an error as there is no such attribute. It seems to me there is no facility for this in the gem since the requirement came into existence after the gem was created. I have not been able to find any other gems to connect with ebay. I have also noticed, there are very little complaints about this even though people are still downloading the gem (10 people downloaded it today). I think there are quite a number of people writing for ebay. Is there a key word I am missing to specify the condition? A work around that people have been using? Another gem I have missed?
There is an existing item_conditions_codes.rb in the gem's type directory and only has two values New and Used. Guess you could add more values in there. However still needs mapping to ID's per the updating (and changed from Attributes) method
You have to modify in the gem library in .. ruby/1.8/gems/ebayapi-0.12.0/lib/ebay/types/item.rb
and add the following new lines
# added to allow ConditionID to be pushed into XML
numeric_node :condition_id, 'ConditionID', :optional => true
then in your ruby ebay code use the following convention
:condition_id => 1500,
At least that seems to work for me right now.

Apotomo: How do you render a state/view that's in HTML format from another view that's in another format?

For reasons beyond this problem, I need to respond with JSON when creating an image:
<%=
raw({
...
:url => #image.url(:width => #width, :height => #height),
:edit_link => render({:state => :image_edit_table_cell, :template_format => :html}, #image),
# btw, I've also tried passing :format => :html
:delete_link => link_to_destroy_image(#image, :remote => true, :path => url_for_event(:destroy, :image_id => #image)),
...
}.to_json)
%>
However, in that JSON, I want to include some pretty fancy HTML. To include that, I render a state/view (as you can see in the :edit_link portion). This is the image_edit_table_cell.html.haml view of the widget:
= link_to_edit_image #image, :remote => true
# ... doesn't really matter - as long as you know this is html.haml
However, when I create an image, and the JSON is rendered, I get a Missing template error:
ActionView::Template::Error (Missing template cell/rails/image_edit_table_cell with {:handlers=>[:builder, :rjs, :rhtml, :erb, :haml, :rxml], :locale=>[:en, :en], :formats=>[:json]} in view paths "/home/ramon/source/unstilted/app/widgets", "/home/ramon/source/unstilted/app/widgets/layouts" and possible paths image/table/image_edit_table_cellapplication/image_edit_table_cellapotomo/widget/image_edit_table_cellcell/rails/image_edit_table_cell):
6: :caption => #image.caption || "",
7: :text_tag => #image.text_tag(:width => #width, :height => #height),
8: :url => #image.url(:width => #width, :height => #height),
9: :edit_link => render({:state => :image_edit_table_cell, :template_format => :html}, #image),
10: :delete_link => link_to_destroy_image(#image, :remote => true, :path => url_for_event(:destroy, :image_id => #image)),
11: :success => true
12: }.to_json)
app/widgets/image/table_widget.rb:37:in `image_edit_table_cell'
app/widgets/image/table/new_image.json.erb:9:in `_app_widgets_image_table_new_image_json_erb___457172591_99648970_0'
app/widgets/image/table_widget.rb:16:in `add_image'
app/widgets/image/uploader_widget.rb:22:in `upload'
It seems like the problem is that since I'm rendering it from a JSON file, it doesn't know to look for an HTML file (thus the format it's looking for is json. That's why you see the :template_file => :html option (I got that from here) in the first block of code above.
I'm using these gems:
'rails', '3.0.10'
'cells', '3.6.2'
'apotomo', "1.1.2"
Apparently, this is a Rails issue, not an Apotomo issue. This answer did it for me! Key is setting the format in your view file before you render your html view:
<% self.formats = ["html"] %>

Testing Paperclip file uploading with RSpec

I don't really care about testing file uploads, but since I have validates_attachment_presence, etc.. in my model, rspec is complaining.
So now I'm creating my model with these attributes in the spec to try and shut it up:
#attr = {
:name => "value for name",
:title => "value for title",
:content => "value for content",
:pic_file_name => "example.jpg",
:pic_content_type => "image/jpg",
:pic_file_size => "8192",
:pic_updated_at => nil
}
This doesn't work, though.
I found this: http://fr.ivolo.us/posts/mocking-paperclip-with-rspec
So I tried something like this:
Post.should_receive(:save_attached_files).and_return(true)
Which doesn't work either. How do I appease RSpec?
If the model has_attached_file :pic, you should be able to just point the pic attribute at some file and all should be dandy.
Meaning something like #attr = { :pic => File.open(File.join(Rails.root, 'spec', 'fixtures', 'file.png')) }

Resources