There is a flash video player for html embedding here.
A embed code generator for the player can be found here.
You’ll need an actual java version.
Download the ruby installer here and install to a directory of your choice (i.e. c:/rubies/jruby_xxx).
Go get pik: Download site and run the installer.
$> gem install rails
Done!
Capybara is not a drop-in replacement and does not have the same API. I’ll collect differences here:
Webrat | Capybara |
---|---|
response.should | page.should |
contain | have_content |
Other gotchas: * fill_in does not work with symbols as the fieldname on capybara!
Assume you have a Customer model and a namespaced controller for handling customers:
class Platform::Backend::CustomersController < Platform::BackendController . . . end
Then, the right form_for tag is the following:
<%= form_for([:platform_backend, @customer]) do |f| %> . . . <% end %>
When you get a “Stack level too deep” error, for all step definitions:
Feature: Create a customer So that a new customer can access his archive As a platform admin I want to be able to create a new customer Scenario: Create a customer # features/platform_backend/create_a_customer.feature:7 Given I am logged in # features/platform_backend/step_definitions/create_a_customer_steps.rb:1 When I create the customer John Doe Company # features/platform_backend/step_definitions/create_a_customer_steps.rb:8 stack level too deep (SystemStackError) features/platform_backend/create_a_customer.feature:9:in `When I create the customer John Doe Company' Then I should see the John Doe Company in the customer list # features/platform_backend/step_definitions/create_a_customer_steps.rb:15 Failing Scenarios: cucumber features/platform_backend/create_a_customer.feature:7 # Scenario: Create a customer 1 scenario (1 failed) 3 steps (1 failed, 1 skipped, 1 passed) 0m2.483s
you have been bitten by a bug in rspec v2.5. You can solve this, by specifying a later version in your Rails.root/Gemfile
:
group :test, :development do gem 'rspec', ">= 2.6.0.rc2" gem 'rspec-rails' end
In your Rails.root/config/routes.rb
:
Archive::Application.routes.draw do . . . root :to => proc { |env| [200, {}, ["Welcome"]] } end
Applying a rails application template after having created the applicaton:
rake rails:template LOCATION=/path/to/template
I’ve just written my first feature in cucumber and I’m thinking about the best way to organize features and steps.
I’ll give a try at following structure:
Rails.root |-features |-[business_need] |-[feature_n].feature |- step_definitions |- [feature_n]_steps.rb
In reality, it looks like this:
Rails.root |-features |- platform_backend |-create_a_customer.feature |- step_definitions |- create_a_customer_steps.rb
To have autotest run your cucumber features, you habe to set AUTOFEATURE to true, before running it:
$> AUTOFEATURE=true $> autotest
Modify your Rails.root/Gemfile
:
group :test do gem 'cucumber-rails' gem 'capybara' gem 'database_cleaner' end
Install your bundle:
$> bundle install
Install cucumber with rspec and capybara:
$> rails g cucumber:install --capybara --rspec
babypips.com has a japanese candlestick chart cheat sheet here
There is a zip gem for Ruby. You can find it here
First, you have to install the zip gem:
$> gem install zip
or, when using rails, you can add it to your Rails.root/Gemfile
:
gem 'zip'
Then you can do something like this:
require 'zip/zip' Zip::ZipFile.open("output.zip", Zip::ZipFile::CREATE) do |zip_file| zip_file.add "filename_in_the_zipfile.txt", "some_source_file.txt" end
I did find some fancy examples, but I wanted to have it look nice, so I came up with this:
File.new('some_file.txt', "r").lines.count
File.open('some_file.txt', "r") do |file| nth_line_content = file.lines.entries[n] end
Create the application:
$> rails new [APP_NAME] -d [DB_ADAPTER] -m http://jruby.org/rails3.rb
Add warbler to your app. Edit Rails.root/Gemfile
:
group :development do platforms :jruby do gem 'warbler' end end
Install your bundle:
$> bundle install
Check the installation:
$> rails server
Open http://localhost:3000
.
If you are using sqlite for production, you may want to include the Rails.root/db
to the war file. To do this, you’ll have to create a warble config file:
$> warble config
Then, edit Rails.root/config/warble.rb
:
Warbler::Config.new do |config| config.dirs = %w(app config db lib log vendor tmp) . . . end
Convert the application to a .war file:
$> warble
Install Tomcat. Copy the .war file to the tomcat/webapps folder. Open a browser at http://localhost:8080/manager (admin:admin) and enable your application.
Open http://localhost:8080/[APP_NAME]
Wie golem.de berichtet ist ein ausgestelltes Hausverbot gegen die GEZ rechtens und wirksam.
Das ist doch mal eine gute Nachricht. Leider kommt das Urteil (und auch die Klage) etwas spät, da die Zeiten der GEZ-Belästigungen sowieso bald vorbei sein sollten, da bald jeder Haushalt pauschal zahlen “darf”.
There is a Blueprint CSS generator at ianli.com
Es gibt einen neuen Bericht der FR zu diesem Thema: Kirche für strengere Kontrollen zum Tanzverbot
I often use nested resources in rails. And I like to use scaffolds to have a start, when developing. But there is no nested scaffold in rails 3 by default.
Akira Matsuda has written one
Assume you have projects that belongs to a customer. You can define a factory like that:
Factory.define(:customer) do |customer| customer.email "customer@example.com" customer.password "foobar" end Factory.define(:project do |project| project.name "Example project" project.description "This is an example project" project.targeted_at DateTime.now.advance(:days => 7) project.association :customer, :factory => :customer end
To add pretty urls to your blogs posts, you can use the friendly_id
gem, that can be found here.
The documentation is really good, and installing was straight:
Add the gem to your application. In your Rails.root/Gemfile
:
gem "friendly_id", "~> 3.2.1"
Install your bundle:
$> bundle install
Run the friendly id installer:
$> rails g friendly_id
Migrate:
$> rake db:migrate
Edit Rails.root/app/models/post.rb
:
class Post < ActiveRecord::Base has_friendly_id :title, :use_slug => true, :approximate_ascii => true, :ascii_approximation_options => :german # support for german umlauts
Generate the slugs for existing posts:
$> rake friendly_id:make_slugs MODEL=Post
There is no step three :)
Assume you have a i18n toolbar on your page. To switch between locales, without switching the current page, you can link to the locale without setting any path:
<%= link_to image_tag("application/icons/german.jpg"), url_for(:locale => :de) %> <%= link_to image_tag("application/icons/english.jpg"), url_for(:locale => :en) %>
I hereby promise, that i’ll never forget the “Set Union” operator again.
The Ruby API says: Set Union—Returns a new array by joining this array with other_ary, removing duplicates.
[ "a", "b", "c" ] | [ "c", "d", "a" ] #=> [ "a", "b", "c", "d" ]
</cite>
Highlighting the current link is a pattern, that you’ll need on almost all pages.
I googled the problem and got to this page. Some guy posted a comment with a link to here. I liked the approach from the moment i saw it. Unfortunately it didn’t work “out-of-the-clipboard” (seems to be for rails 2.x), so I had tweak it.
Here is what I came up with:
Rails.root/app/helpers/application_helpers.rb
:
module ApplicationHelper class CurrentPageDecorator def initialize(helper,options) @helper = helper @html_class = options[:class] || 'active' end def link_to(*args,&blk) name = args.first options = args.second || { } html_options = args.third || { } if @helper.current_page?(options) html_options[:class] = (html_options.has_key?(:class)) ? "#{html_options[:class]} #{@html_class}" : @html_class end @helper.link_to(name,options,html_options,blk) end end def highlight_current_link(options = { },&blk) raise ArgumentError unless block_given? yield CurrentPageDecorator.new(self,options) nil end end
In your views:
<ul>
<%= highlight_current_link do |n| %>
<li class="span-6" id="clinic">
<%= n.link_to 'Klinik', template_path("praxis/clinic"), :id => 'clinic_link' %>
</li>
<li class="span-6" id="office_tour">
<%= n.link_to 'Office Tour', template_path("praxis/office_tour"), :id => 'office_tour_link' %>
</li>
<% end %>
</ul>
To pass a custom html class for the active link you can do: <%= highlight_current_link(:class => ‘on’) do |n| %> . . . <% end %>
There is a programming language popularity index @ TIOBE Software
Sometimes it’s difficult to find the best solution or gem for a specific problem in ruby. The Ruby Toolbox has statistics about the popularity of gems orderes in categories: