How to raise 422 error in Rails

I was updating error pages to follow latest GDS standard (https://design-system.service.gov.uk/patterns/). I needed to test the 422 page.

After few failed attempts I found this solution to work, just put this code in your index method on your home page:

    raise(ActionController::InvalidAuthenticityToken)

I hope it helped.

CarrierWave file exists?

If you ever wondered how to check for file if exist while you were using carrierwave gem with storage on amazon S3 here is how.

Assuming you have User class:

class User < ActiveRecord::Base
  mount_uploader :avatar, AvatarUploader
end

and uploader class
class AvatarUploader < CarrierWave::Uploader::Base
  storage :fog
end

then only thing that you have to do is this

user = User.first
user.avatar.file.exists?

thats it. I kind of assumed that it should be simple avatar.exist? but you have to get fog instance of file to be able to access exists? method.

Looking for Ruby on Rails contract

To follow my passion which is writing my own applications and running, I decide to leave  Unboxed, where I had really great time. I was there almost 2 years and during that time I learn a lot, met lot of interesting people and work on lot of different types of projects. This is list of my projects that I was working on and my role.

education.skype.com

simple platform, designed to enable teachers to connect, share their resources and start collaborative projects. Winner of Core 77 design award 2011. Responsibilities included:

  • Lead Back-end developer and Technical Architect
  • Performance optimisation for current 14000 active users
  • Skype API integration (Authentication)
  • integration with Amazon S3, SES (Emailing service), EC2 (Cloud hosting)

Skype New Year Eve

To bring in 2011 Skype launched an HTML5 site that tracked NYE as it happened around the world. Users uploaded videos to YouTube via the site which, in turn, were displayed on an interactive timezone map of the world. The site was designed to work across multiple platforms in including mobile and tablet optimisations. Responsibilities included:

  • Lead Back-end developer and Technical Architect
  • YouTube API integration with download performance optimisation

Skype Theme

Skype Theme is site where Skype Apple users can upload themes for Skype UI. Responsibilities included:

  • improvement of unsecured parts of application. Based on Security report from independent agency.

Extra special trust

The ExtraSpecial Trust is charity that offers small personal grants towards some of life’s important extras to help make a wish come true. Responsibilities included:

  • finishing of html templates
  • deployment set up for Heroku
  • Amazon S3 integration

Edna (Channel 5)

The Edna is programme database. It has been design to streamline the working processes of the Digital Media team. It provides sources programme, series, episode, cast and VOD availability data from a variety of sources for different sites. Responsibilities included:

  • integration with Movida (programme database)
  • export dat in XML and JSON – contained information are based on type if requested player or platfiorm

If you are interested to work with me you can sand me an email to petr(at)zaparka(dot)cz or if you are just interested what am I up to just follow me on twitter @zaparka

How to add second mysql server with installed WAMP

Because I started  learning Ruby on Rails I needed to run some database server for ruby. I like mysql.  I developing web aplications with WAMP (Windows + Apache + Mysql + PHP). So i tried to run Ruby on Rails with pre-installed version of mysql 5.1.33 but Rails didn’t work properly. I tried to find how to fix the problem bud it seems that Ruby on Rails has  some problems with mysql 5.1.33.

So i refused SQLite and PostgreSQL for my personal reasons, than only one option left, another mysql server. I downloaded mysql server 5.0. run installation and than configuration that failed in last item (security settings). But mysql server worked quite well.

I was wondering if Rails are going to accept another sqlserver. It didn’t let use say it did but i forget set different port to mysql server 5.0. So i had an idea that this port problem can cause the security problem. So i run configuaration tools set port to 3309 and click to final step and security problem appeared again.Never mind I thought. I added a line port: 3309 as you can see below,

development:
adapter: mysql
encoding: utf8
reconnect: false
database: blog_development
pool: 5
username: root
password: my_passwd
host: localhost
port: 3309

to database.yml in config folder of my project and run rake db:create.

Rails worked fine and WAMP too :).

So in short, you only need to set a different port to run 2 mysql servers at one pc.

PS: It may occur Error mesage  like:’ libmySQL.dll missing ‘ or something like that. You will fix this by copy libmySQL.dll from installed mysqlServer 5 directory (installedpath/mysql server 5.0/bin) to your ruby directory (installedpath/ruby/bin).

Start learning Ruby and Ruby on Rails framework

I has been developing Internet aplication about 9 years. In everyday work i use  PHP and AJAX technology. It is quite a long time ago when my friend Ladislav Martincik told me  about Ruby on Rails. I seen some amazing presentation of Rails framework he showed me. I wonder why I did not start learning and using Rails and Ruby at  that time. Maby it was too early for me or maybe i was  too lazy.

But …

I starting now. I bought book Begining Ruby on Rails last week. But the book seems to me that is little confusing. So i was browsing a little and I found this cool book called  ‘Poignant Guide to Ruby”. It is kind of unconventional but i love it. It is funny and very brightly written.  I’m looking forward to read more chapters tomorow.

Ps: I wonder how high can insects fly, because I live at 8th floor and it still bothers  me.