Rails console shortcuts
Contact me at LinkedIn  RailsZilla at Facebook  RailsZilla at twitter   google +1  Contact me at Xing  connect me at github

Rails console shortcuts

Posted in console, Rails, Start

I always forget all those handy hints in Ruby on Rails, while using my Rails console. Here I will drop some very useful console commands to get some daily jobs done: Hint No.1 Sometimes we change the code in a file. In that case we can reload the changes in the rails console by using […]

Tags: , ,

Generate polymorphic URL in Rails

Posted in Rails

In this example, I want to explain a best practice for Polymorphic URLs in Rails. I will show really bad things here as an illustrative example. Don’t worry, we will refactor the code later ;-) Let us assume that we have three models, Post, News and Comment. In most cases, a post has many comments […]

Tags: , , ,

ActiveAdmin with http authentication

Posted in Rails

Ever asked yourself how to use HTTP Basic authentication with ActiveAdmin? There are several reasons to use HTTP Basic authentication for your backend. I needed a solution which can be recycled wherever I need a HTTP Basic authentication. I only wanted a central place for User and Password and I wanted just one call wherever […]

Tags: , , , , , ,

Why the Rails default_scope is a bad thing

Posted in Rails

Activerecord provides default_scope to set a default scope for all operations on the model. I was never a friend of using default_scope, even when many friends used it in their projects. At the first look, it looks convenient but will lead to a headache very soon. We should avoid using it and here is why: […]

Tags: ,

Rails Security – Clickjacking

Posted in Rails

Note: This exploit is fixed in Rails 4 Our exploit today is clickjacking which is also called “UI redress attacks”. With clickjacking you can take an unexpected action for your victim by rendering the target site in an invisible frame. As an example, an attacker may trick users into taking undesired actions like making a […]

Tags: , , , ,

Security issue – symbol DoS vulnerability in ActiveRecord

Posted in Rails

There is a symbol DoS vulnerability in Active Record. When a hash is provided as the find value for a query, the keys of the hash may be converted to symbols. Have a look at this example: 1User.where(:name => { ‘foo’ => ‘bar’ }) When you write this small piece of code, the string ‘foo’ […]

Tags: , , ,

rails – uninitialized constant dashboardcontroller

Posted in Rails

This is a quick hint: If you play with ActiveAdmin and get the error: “uninitialized constant dashboardcontroller” open your routes.rb in your /config-folder. Now look for: 1root :to => ‘your_controller#index’ You have to be sure, that your root definition is before 12devise_for :admin_users, ActiveAdmin::Devise.config   ActiveAdmin.routes(self) So your routes.rb could look like 12345YOUR_APP::Application.routes.draw do   […]

Tags: , ,

undefined method visit for RSpec

Posted in Rails, Ruby

Writing full-stack tests is important. In this article it’s all about behavior-driven development (abbreviated BDD) and fixing the errors which can occour. I have three simple steps to check that your test will run. Lets say we use the following Integration Test in our static_pages_spec.rb: 123456789require ‘spec_helper’ describe "Static pages" do   describe "Home page" […]

Tags: , , , , , ,

Chip Online – Ruby on Rails book review

Posted in coffee break, Rails

Happy new 2013! Because the world didn’t end in 2012 (you know, Maya calendar and conspiracy …) I had a bit time in my holidays over Xmas and wrote an article at http://blog.chip.de/itrezensionen. For those who never heard about this site: You can find there tons of reviews for IT books. Whenever you want to […]

Tags: , ,

Rails input size is 30 chars

Posted in coffee break, Rails

Just a quick fix, but leads often to confusion … Let’s say we have a form 1<%= form_for link , url:link_path(link) , remote:true do |f| -%> now we want to insert an input field like 1<%= f.text_field :email, placeholder:’Email’, :title => ‘email’ %> this will will give you a HTML like this 1<input type="text" title="email" […]

Tags: , , , , , ,

Copyright © 2011-2017  - RailsZilla – Ruby on Rails tutorials, tips and tricks All rights reserved. | Imprint | Privacy