How to implement badgeville in ruby on rails - 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

Related

gem rich don't apperas in Active_admin

I installed gem rich in my Rails 4.1.5 project. I'm using Active Admin. In my file of admin I have this line that calls rich:
f.input :content, :as => :rich, :config => { :height => '200px' }, :label => 'Conteúdo'
But when I open Active_admin, the rich don't appears (should appear right below the first field):
My gemfile:
gem 'rich', :git => 'https://github.com/kreativgebiet/rich.git'
In my application.rb I have this lines:
config.assets.prefix = '/lince/assets'
config.relative_url_root = '/lince'
config.action_controller.relative_url_root = '/lince'
When I try without this lines, rich works fine.
Anyone can help me? I can't understand why this not working.
Thanks.
rich has not been updated in years. I recommend you look at other WYSIWYG editors

Solidus / Spree Override not working

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")

ActionDispatch::Http::Parameters#encode_params tries to modify frozen strings and raises on upgrade from Rails 3.0 to Rails 3.2.16

Basically, this seems to be https://github.com/rails/rails/issues/7725 reported a year ago by a guy who stopped responding (heh http://xkcd.com/979/)
and I got this when upgrading from the very last Rails 3.0 to Rails 3.2.16.
The route in question serves HTML from model Page on routes of form /en/contact for example (from config/routes.rb)
# pages
STATIC_PAGES.each do |slug, desc|
match ":language/#{slug}" => 'pages#static_page', :defaults => {:slug => slug, :language => 'en'}, :via => :get, :as => slug.underscore.to_s
end
My attempts to make a sample application that does the same thing and breaks have failed (copied relevant parts of the app into a new app, copied the Gemfile & Gemfile.lock and tried to reproduce, all went fine)
This is the stack trace: https://gist.github.com/bbozo/8315184 - not a single line from my app in it
Again, it's one of those argh, a ghost issues, if anyone has a hunch where to hunt for it, you'll make me VERY happy
:-/
Duping the key from hash iterator fixed it for me,
# pages
STATIC_PAGES.each do |slug, desc|
match ":language/#{slug}" => 'pages#static_page', :defaults => {:slug => slug.dup, :language => 'en'}, :via => :get, :as => slug.underscore.to_s
end
problem here was that STATIC_PAGES is a hash constant with String keys, it's keys are frozen. In cases of requests for which route defaults kicked in the router tried to do something with the frozen slug string stored in :defaults => {:slug => slug - something in the rails 3.0 => rails 3.2.16 changelog introduced a modification of this value and shiny exceptions happened in the ActionDispatch stack.
"Unfreezing" slug by doing slag.dup fixed the issue

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.

Rails: generate a full URL in an ActionMailer view

I'm using ActionMailer to send a sign up confirmation email. The email needs to contain a link back to the site to verify the user, but I can't persuade Rails to generate a full URL (including the domain etc).
I'm using:
<%= url_for :controller => 'login', :action => 'verify', :guid => #user.new_user.guid, :only_path => false, :host => 'http://plantality.com' %>
in my view
Part b:
In development mode Rails gripes if I don't specify the host explicilty in the link above. But I don't want to do this in production. Any solutions?
To solve the problem to pass a host for generating URLs in ActionMailer, check out this plugin and the reason why I wrote it.
To solve the first issue, use named routes when applicable. Instead of
<%= url_for :controller => 'login', :action => 'verify', :guid => #user.new_user.guid, :only_path => false, :host => 'http://plantality.com' %>
assuming the route is called login, use
<%= login_url(:guid => #user.new_user.guid) %>
Note, I'm using login_url, not login_path.
I'm not sure if it is what you want but in config/environments/development.rb you can specify default options for mailer urls
config.action_mailer.default_url_options = {
:host => "your.host.org",
:port => 3000
}
you can do the same in config/environments/production.rb
I don't know why the previous solutions seem so complicated, but since I'm here why not give my 2 cents...
Go to /config/environments and add:
config.absolute_site_url = 'your site url'
for the respective environment (ie. in development.rb, test.rb, or production.rb). Restart web server.
This allows you to call Rails.application.config.absolute_site_url to get the desired URL. No need for plugins or weird cheat, just store the site url as an application wide variable.
I think its not 100% correct way but this can also be a solution :
See the Using asset hosts section in the documentation. You need to specify an asset_host. You can also construct it dynamically from the request chaining "#{request.protocol}#{request.host_with_port}/login/?guid=#{#user.new_user.guid}"
To generate url, try this
Rails.application.routes.url_helpers.user_url(User.first.id, host: 'yourhost.io')
this will generate url like this:
http://yourhost.io/users/1
As well you can pass some params
expires = Time.now + 2.days
params = {expires: expires}
u = User.first.id
Rails.application.routes.url_helpers.user_url(u, params, host: 'host.com')
will generate:
http://yourhost.io/users/1.expires=2018-08-12+15%253A52%253A15+%252B0300
so you can werifi in action if link is not expired

Resources