Chronicling my experiences with ruby on rails, web application development/management.

Showing posts with label plugins. Show all posts
Showing posts with label plugins. Show all posts

Tuesday, May 5, 2009

Upcoming update to Theme support plugin

I'm updating the theme support plugin to work with 2.3.2 now. jystewart has done a tonne of work with it, but his plugin doesn't yet use the helpers, which my version does.


We'll either combine forks or go our separate ways depending on how things play out, so stay tuned!!!


Here is the theme support repo on github. Follow the fork link to jystewart's if interested.


UPDATE - Use jystewart's github theme support for 2.3.2 and mine for 2.2.2 rails app

For some stupid reason the core guys flip flopped on a code insertion that screwed up 2.2.2 and I had to fix it so that the helpers worked in rails 2.2.2.

However, now that they reverted to code from 2.1.2 in 2.3.2, the old helper methods, which the jystewart version didn't touch, work fine. So rather then mess with it, it's easier just to use jystwart's version.

Lastly, in rails 3.0 i think it will revert again, so stay tuned.

Saturday, March 14, 2009

Creating a Rails Plugin - thoughts behind Active_Affiliate

I'm about to launch a new whizbang plugin. Really excited about it as i think it will add something to the Rails community and show that i have learned SOMETHING over these last 18 months.


I just wanted to document the thought process for this plugin, without talking about the code. Hopefully you find it interesting, or even helpful


Thought Process


I started with the premise that if you run a successful web app, that charges a membership/account fee, you will need some way to bring in new customers. Affiliate programs are a way to leverage the Internet Marketing initiative and your app.


There really are just two main players in the affiliate space, commission junction and Linkshare. There isn't anything wrong with these programs and chances are you'll need them too, but hosting your own affiliate program and managing it how you want, was a dream i wanted to fulfill.


Since i code in rails, and there was no solution, i created one. Here are some of the features.


  • Affiliate Signup through a route /affiliates

  • Affiliates get their own unique code

  • Primitive banner ad generator that will populate link with their code

  • Affiliate code tracking put in session variables, and saved on customer purchase, through your checkout/signup sheet.

  • Currently, paypal id's are needed so the user can get paid.

  • Reporting for both the Affiliates and App Management.


I'll be updating active_affiliate on github as features are implemented.

Wednesday, January 21, 2009

theme_support and formatted routes (rss feeds)

Today I was trying to get my web app to allow subdomains to provide an rss feed. it didn't work.



I'll be posting a solution when one is found, however, i'm hoping this wasn't pebkac again.



Solution


In your controller, where you are making the rss call, you must render layout false. Here is an example:

format.rss { render :layout => false }
I'll file this one under the learn something new, that is easy, everyday column.


After some investigation, it appears that theme_support plugin doesn't support themed rss feeds, when you enter them in the head section of an html page. I'm working to allow this in the plugin.

Saturday, December 20, 2008

Solved: ApplicationController has been removed from the module tree error.

A copy of ApplicationController has been removed from the module tree but is still active!
You got this error... and now you don't know what to do. Well i can offer a suggestion or two on how to fix it.

Symptoms


You may be trying to update a plugin that is conflicting with ApplicationController. You'll also notice that this error happens when you try to reload the same page, or even move a different view within the same directory. For instance, if you load plugin/index and the try to reload OR go to another link say plugin/new, you get this error.


Hit me nerbie69! Solve my problems


Well dude, you got way too many for me to solve, but this one is on me.


All douchery aside, i solved my error by deleting some of the leftover cruft of having a generator plugin, that i converted into a engines based plugin. github nerbie69/railstat plugin check out the forked project for the current generator based script.


#OLD code
require_dependency 'path_tracker'

class RailStatController < ApplicationController
include PathTracker

before_filter :extract_subdomain
....


#new code notice the difference
class RailStatController < ApplicationController
unloadable
include PathTracker

before_filter :extract_subdomain
...



Since ApplicationController is an unloadable class, we too had to match it's unloadability in our app/controllers directory of our engines based plugin. Also, we don't need the require statement, as you do when you are using a generator plugin, if you are referencing the lib directory. The engines takes care of that for you too.


Wrap it up Johnny!


Ok, engines rock. Also, you can apply this code to any of these stupid errors you might get in the future for other controllers and plugins.


Sources: rails trac from 2006.

Tuesday, December 16, 2008

Rails Engines are awesome!!!!

Some of my loyal fans may be shocked to know that i just tried the Rails Engines plugin. Officially titled engines plugin on github.


So easy, and exactly as advertised


Sometimes, try as we may, things aren't always as advertised in this community of ours. So it is a good when things go exactly as planned


Instructions on using the plugin are well written in the README, so i won't bore you with those details, but if you have ever wanted to make a plugin that had the same familiar structure as your rails app', then this is for you. All you need to do is create a plugin and then add the same app directory structure in the root folder of the plugin.


Predictions


Theoretically you can make all of your controller, models and views as plugins, making your app act almost like it's own SAAS appliance. If you have a generator style'd plugin, there is no reason not to use engines. Less coding for you, the plugin creator.


Examples of Hot Rails Engines Action (HREA?)


In fact, i just put the finishing touches on my fork of the rails stat plugin, that was purely a generator script, basically. Now in my forked version, the engines plugin takes care of generating static code within an app. And that is pretty frickin cool.

Saturday, December 13, 2008

Working with Generators in Rails - Lessons Learned the hard way.

I'm updating a plugin that works in Rails 2.2.2 development, yet borks in a production site using 2.1.0.

undefined method `render' for # Rails::Generator::Commands::Create:0x7fdf1caaa2c8


right now, Here is what the problem was


in my generator script i had the usual code
m.template "app/views/rail_stat/hits.rhtml", "app/views/rail_stat/hits.rhtml"
m.template "app/views/rail_stat/lang.rhtml", "app/views/rail_stat/lang.rhtml"

Now inside of hits.rhtml is the following line
< %= render :partial => 'menu' % >

For some reason the render part fudges everything up. if i delete that line, the files go through with no problem.


Solution


When generating erb templates, the Rails::Generator needs to use an extra percentage sign whenever you call specific erb calls. For instance, i only had used < %= render :partial => 'menu' % > but i should have used < %%= render :partial => 'menu' % >
Again, notice the extra % percentage sign in the second code bit. I'm sure there may be a better reason but the second % sign acts almost as a buffer and tells m.template to print the erb code in the new file? Again, that may be too simplistic of an answer, but that is what it seems like to me.

Tuesday, December 9, 2008

Finally. Theme_Support fully Working in Rails 2.2.2

I feel like singing. That is how happy i am.


Theme_support plugin for rails is fully working in Rails 2.2.2


I'll work with jystewart from github to get the fix onto his version, as that is what i got to work. Here is the link to Theme_support on github. Alegria!

Wednesday, December 3, 2008

Theme Support plugin update for Rails 2.2- Part 2.

So i have tried my damnedest to make this work. I get an error as follows:

undefined method `compute_public_path' for #
So, for some reason in theme support i am getting this crazy error, where in Rails 2.0.2 i did not, and in another project, which was Rails 2.1.2 using the "old" theme support, i did not get either


Possible Solution (TBD)

It appears that the compute_public_path method is now a private method of the class AssetTag in the module ActionView::Helpers::AssetTagHelpers.

What I still need to figure out


How in the hell do i link this 'sub class' AssetTag to the Module line in the rhtml_helpers.rb file in theme_support? I've tried various configurations to no avail. Who out there is a plugin god and can help out?

Tuesday, December 2, 2008

Theme Support plugin update for Rails 2.2

Commentary: This plugin always has to be updated after every version of a rails upgrade? I don't know why that is however? Perhaps it's the most unluckiest of plugins? carma? something... but like a trooper, it keeps on licking and ticking.



If you are using theme support and have recently upgraded your app to 2.2, you'll need to fix this plugin before you get anywhere. luckily jystewart from github has patched the plugin to work with 2.2. from what i see it may even fix it for a while, so that finally we won't have to keep patching this thing.



URL: http://github.com/jystewart/theme_support/tree/master

Sunday, November 23, 2008

Acts as ferret : only have one instance per development computer...

Symptoms


I kept getting this stupid error
(druby://localhost:9010) /Users/nerb/.gem/ruby/1.8/gems/activesupport-2.1.2/lib/active_support/dependencies.rb:279:in `load_missing_constant': uninitialized constant Browser (NameError)


How to solve this error


Basically I got this error because Acts as ferret was running in another app on my development box. Just do a simple script/ferret_server stop in the OLD app. Return to the new app and start the ferret server by doing script/ferret_server start


Hell, i thought it had to do with my recent updating of rails to 2.2.2, however, it did not.

Sunday, November 16, 2008

Recurring Payments using PayPal Express and Active Merchant

I needed a payment solution that took recurring payments for my rails app. Most of the tutorials out there use either a US based merchant account provider, or are based in the UK. I guess canadians are out to lunch. Oh, and what's worse was that none of them really touched on subscription based models, or as it turns out, recurring payments.


Caveat: Now i am not here to take credit for what I'm about to write. I only write this post as a 'mashup' of two great men and their tutorials on the subject. I just took these two tutorials and used the good from both of them to come up with what you are about to read.


The fine men who authored these posts


Cody Fauser - Active Merchant extraordinaire


Cody is from all accounts the man, if not only the public face, of Active Merchant. His Active Merchant Peepcode pdf (a must read and only 9 bucks!) is the go to guide for learning all about Active merchant from the man himself.


Jon Baker - Paypal Express Recurring Payments add on for Active Merchant Plugin


From his homepage"As well as leading the Rich internet Application at Trigger Software Ltd, he is CEO and Entrepreneur of Vibrant Apps a small company based in Cornwall that makes useful and useable apps."


On with the show...


Basically, i used the framework from Cody's Paypal Express Payments with Active Merchant for my controller/view actions and I used the plugin extension from Jon's post Paypal Express Recurring Payments using Active Merchant.


The sum of these two parts became what i needed to get a basic subscription for my app, and now for you too.


Gimme the High Level overview nerbie69!


Will do. Oh, and i assume you already know how to create a rails app, and that you are following usual rails behaviour and will know that everything in here is based off of being inside your rails app, when you run any code. This tutorial is probably above beginners so i assume anyone reading this kinda knows what they are doing and are just stuck at how to implement subscription based models easily.



  1. Create your Paypal Sandbox developer account and instantiate an API credential from your seller account

  2. Install Active Merchant from github

  3. Insert Jon Baker's Paypal express Recurring Payments nv . rb file in your new Active Merchant plugin

  4. Create your controller and views

  5. Test your new subscription model in your browser

  6. Pinch yourself... it was that easy.


So there you have it. It's the simple steps version of what you are about to do.


Step One - Create your paypal sandbox developer account


Go to https://developer.paypal.com to set up your paypal developer account.
You can find better instructions on the developer site, but it isn't too hard and out of scope for this tutorial. However, make sure you get the api credentials from the Seller account(_biz). I.e., you must log in as the seller, in the sandbox, and follow Cody's instructions on how to set up the API.


Step Two - Install Active Merchant


Go to github and install the Active Merchant plugin: script/plugin install git://github.com/Shopify/active_merchant.git I'm using the plugin here because it's easier to add a file, which is the next step.


Step Three - Adding the paypal_express_recurring_nv.rb file to Active Merchant


Download or copy and paste the following file paypal_express_recurring_nv.rb and put it in the following directory: /vendor/plugins/active_merchant/lib/active_merchant/billing/gateways/

The plan is to get this into active merchant in a future release. We all have a part in making sure this happens, by emailing activemerchant's maintainers and saying how helpful this was. Plus then we can fix any bugs and extend to make it even better.


Step Four - Create your controller and views in your rails app


From here on out is where i mashed the two tutorials together. First create your controller and views: script/generate controller subscriptions index confirm cancel error


Now add the following, as Cody says, to the top of your application.rb controller
include ActiveMerchant::Billing
Also, don't forget to put your ActiveMerchant into test mode, as outlined in his tutorial.


I'll paste the full controller code, so you can see it in all it's glory. Notice, as Cody says, we didn't need a view for checkout, so that is why we didn't add 'it', to the generate code above.class SubscriptionsController < ApplicationController
def index
end

def cancel
end

def error

end

# Confirmation step is the actual step that sends money.
def confirm
response = gateway.create_profile(999, params[:token], :reference => "34")
if !response.success?
@message = purchase.message
render :action => 'error'
return
end
end
# The checkout method used to pass the values to paypal. The description is shown to the user in their paypal account.
def checkout
setup_response = gateway.setup_agreement("Monthly subscription fee $9.99 USD",
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:action => 'index', :only_path => false)
)
redirect_to gateway.redirect_url_for(setup_response.token)
end
private
#Here's the gateway info.
def gateway
@gateway ||= PaypalExpressRecurringNvGateway.new(
:login => 'Seller_232323455_biz_api1@site.com',
:password => 'W32RW53TE64Y7',
:signature => 'A90EWQRLSDA0SA.SAD0FASWEQ4ls0sl20S0SLD0.223.w'
)
end
end


Views


The views are easy to setup and obviously could say anything. Here is what i did, to get a generic subscription message setup:


# Index.html.erb:

< h1 >Site Subscription< /h1>
< p >Thank you for your decision to subscribe to this site.


< p >Your order total is $9.99 / month


< p >
< % = link_to image_tag('https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif'), :action => 'checkout' % >
< / p >

The error messages can stay the same as what cody has, i believe.


The confirm view really doesn't have to say anything other then Thanks! All the magic happens in the controller when the response comes back. I know that i am probably going to add my own app specific controller functions to this confirm, such as creating their profiles and setting certain site variables, now that they have subscribed to become 'one of the cool kids'


Step Five - Test in your browser and revel at your genius


That heading says it all.


Thanks for reading and enjoy.


I hope that you enjoyed this little tutorial. Subscription handling hasn't been easier thanks to Jon Baker, active merchant and all their hard work.