Paymill + Heroku + Rails 4 No Token Found Error - ruby-on-rails

I've integrated Paymill successfully in my ROR4 App using their Paymill Bridge. All works fine in development mode, but as soon as I deploy it to production, it returns me the "NO TOKEN FOUND".
This used to happen in development mode because it was not loading the transactions.js properly due to turbolinks, I have fixed it since.
But cannot make it work in production
Thanks!
All the Best

since the introduction of the assets pipeline, rails uses gem uglier to compress (remove whitespaces, shorten function and variable names, etc.) the custom JavaScript. This is done by the command rake assets:precompile, which is executed on each deploy to heroku.
I think you should take a look at uglifier and try to overwrite the default settings. My first guess is that you have to set :unused to false. Because the PAYMILL_PUBLIC_KEY variable is used by PAYMILL bridge and not by your scripts.
You can test this on your local machine by calling: rake assets:precompile and check the generated JavaScript.

Related

What exactly was initialize_on_precompile used for?

I'm having trouble understanding what initialize_on_precompile was used for. What exactly did it mean for it to be false (especially as it relates to Heroku)? What did it mean for it to be true?
Apologies if this question is too broad/vague, but I can't seem to find the answer anywhere.
This option was available till Rails 3.x as when you run rake assets:precompile it initializes the application and tries to connect to the database. So setting this option to false prevents it. So if you have any issues in connection to the database rake assets:precompile won't work and fail this option ensures that it will work.
From Rails Git Repo:
The initialize_on_precompile change tells the precompile task to run without invoking Rails. This is because the precompile task runs in production mode by default, and will attempt to connect to your specified production database. Please note that you cannot have code in pipeline files that relies on Rails resources (such as the database) when compiling locally with this option.
In Rails 4.x this option has been removed and is no longer required. Rails 4 now always loads initializers and the database configuration before precompiling assets
Source of Commit: https://github.com/rails/rails/commit/2d5a6de

Rails ckeditor extraplugin problems on production

I'm developing a Rails 4.1 application. I use ckeditor
(https://github.com/galetahub/ckeditor), and I'm using some extraplugin
(image2, which also uses widget), stored in app/assets/ckeditor/plugins
directory. I used it with f.cktext_area :extraPlugins => 'image2'. It
works well in development and also in production environment.
Now I decided to add one more extra plugin (syntaxhighlight), stored and
used in the same way (stored in app/assets/ckeditor/plugins , called
with :extraPlugins => 'image2,syntaxhighlight'). In development
environment it works perfectly, but in production ckeditor cannot load
syntaxhighlight plugin, because it try to load not the hashed version of it:
uncaught exception: [CKEDITOR.resourceManager.load] Resource name
"syntaxhighlight" was not found at
"/assets/ckeditor/plugins/syntaxhighlight/plugin.js"
I run "rake assets:precompile" many times, it generated the hashed
version of plugins
(/assets/ckeditor/plugins/syntaxhighlight/plugin-a9ce9661bf06ef29e7ac40baac50c044.js).
But none of the working other (old) extraplugins do not have simple
plugin.js in the public directory, and they work.
Any idea how to make work this new extra plugin?
I had the same problem. To solve this, run:
rake tmp:cache:clear
and after assets:precompile again.
Just to understand what happened: ckeditor gem generate a mapping file (override.js), and it maps the simple and the hashed version of js files. If you insert a new extraplugin, it will not regenerated with assets:precompile, you have to clear the cache to force it.

Why WEBrick server is faster in production mode rather in development mode? + Rails

I have been developing ruby on rails application since some couple of months. I use the default WEBrick server to run the applications. And I found that when I start the WEBrick server in the development and production modes, the server works more speed for production mode than for the development mode.
Is there any specific reason behind that? Can anybody explain me?
In production mode, a server loads code into the cache, which makes things quick. However, that's not the case in development mode (since you don't want to restart your webrick every time you made a change). Every request loads the according code again, which takes a bit of time.
And the most of all time-eaters is the asset pipeline. In production, you get a compiled version of your assets (javascripts and css) in maybe one or two requests. In development, you get them split, for debugging purpose (based on your environment settings, of course). And because a browser does not handle all requests simultaneously, some assets are loaded after other ones are finished loading. You can watch this behaviour with e.g. firebug's network console. That means: the more assets you have, the longer your page takes to load in development mode.
In dev mode classes are not cached, so Rails reloads all the classes each time you refresh. Also, asset compilation is not done in development (by default), so Rails reloads all the assets (CSS, Javascript etc) each time you refresh.
The difference is between 2 environments. In Rails, there are several environment. Each has his own database configuration and Rails options.
You can use the Rails.env variable to made some different change with particular environment.
By default, the development environment is without all cache and activate the auto-reloading. The production environment is with all cache.
But if you want you can make a production environment like development or development environment like production.
You can add some new specific environment too.
Creating new Environment:
Assuming you want create the hudson environment.
Create a new environment file in config/environments/hudson.rb.
You can start by cloning an existing one, for instance config/environments/test.rb.
Add a new configuration block in config/database.yml for your environment.
That's all.
Now you can start the server
ruby script/server -e hudson
Run the console
ruby script/server hudson
And so on.

Running a Rails site: development vs production

I'm learning Ruby on Rails. At the moment I'm just running my site locally with rails server in the OS X Terminal. What changes when a Rails site is run on a production box?
Is the site still started with rails server?
Any differences with how the db is setup?
Note: I'm running Rails 3.
A rails app can be run in production calling rails server -e production, although 99% of the time you'll be serving on something like passenger or thin instead of WEBrick, which means there's a different command to start the server. (thin start -e production for instance)
This is a complicated question, but the best place to start learning about the differences would be to look at the specific environment.rb files. When rails boots up it starts with the environment file that matches the called environment, ie if you start it in development it begins by loading your development.rb file, or if you're in production it will load the production.rb file. The differences in environments are mostly the result of these differences in the various environment config files.
Basically if a Rails 3.1 app is in production mode, then by default it is not going to be compiling assets on the fly, and a lot of caching will be going on that isn't happening in development. Also, when you get error messages they will be logged but not rendered to the user, instead the static error page from your public directory will be used.
To get more insight into this, I would suggest reading the relevant rails guides:
Rails Initialization Guide: http://guides.rubyonrails.org/initialization.html
Rails Configuration Guide: http://guides.rubyonrails.org/configuring.html
There are two contexts you can use the word "production" here. One of them is running the server in production mode. You can do this locally by,
RAILS_ENV=production ./script/server
The configuration for this is picked up from config/environments/production.rb. Try comparing this file with config/environments/development.rb. There are only subtle differences like caching classes. Development mode makes it easier so that it will respond to any changes you make instantly. Plus there are two different databases (by default) will be used namely yourproject_development and yourproject_production if you choose to run your server in either of these modes.
On the other hand, rails deployment to a production box is something different. You will need to pick your server carefully. You may have to deal with a deployment script may be capistrano. You may also need a load balancer such as netgear. The database also may require a deep consideration like size expectation, master/slave clustering etc.,
Note: I have never used Rails 3. This answer is biased towards 2.3.x.

Weird Facebooker Plugin & Pushion Passenger ModRails Production Error

I have an application (Rails 2.3.5) that I'm deploying to production Linux/Apache server using the latest Phushion Passenger/Apache Module 2.2.11 version. After deploying my original application, it returns a 500 error with no logging to production log.
So I created a minimal test rails application, with some active record calls to the database to print out a list of objects to the home controller/my index page. I also cleared out all plugins. That works fine in the production environment. Then I one by one introduced each plugin that I'm using one at a time.
Every plugin works fine EXCEPT facebooker. Every time I load the facebooker plugin into my app/vendor/plugins directory (via script git etc) my test application break (500 error - no error logging). Everytime I remove the facebooker plugin my test application works.
Has anyone seen this before/ have any solutions? I saw this solution but didn't see it in the facebooker code.
Did you add Facebook credentials for production environment?

Resources