# config/environments/development.rb
config.generators do |g|
g.test_framework :rspec
end
In rails there is a nice way to make params required/permitted:
before_filter :example_method
def example_method
params.required(:id).permit(:password)
end
its = model.clone
Forgery(:lorem_ipsum).sentences(3, :random => true)
Order of bootstrap @imports care. For example it raises Undefine mixin ‘ie7-inline-block’
# app/assets/application.css.scss /* *= require_self *= require_tree . */ @import "bootstrap/buttons"; @import "bootstrap/variables"; @import "bootstrap/mixins";
but this not
# app/assets/application.css.scss /* *= require_self *= require_tree . */ @import "bootstrap/variables"; @import "bootstrap/mixins"; @import "bootstrap/buttons";
How to capture the block of code in rails helper? Here you have an example
# app/helpers/menus_helper.rb
module MenusHelper
def link_to_menu(form, options = {}, &block)
name = capture &block
html = render :partial => 'example/partial', :locals => {:f => form}
link_to_function name, html, options
end
end
# index.html.haml
= form @menu do |form|
= link_to_menu form do
%i.icon-menu
Menu
= form.submit
How to create routing like this in rails 3?
/accounts/numbers
First of all, create Accounts::NumbersController
$ rails generate controller accounts::numbers
User :path, :module and :as attributes for scope.
# config/routes.rb
...
scope :path => 'accounts', :module => 'accounts', :as => 'accounts' do
resources :numbers, :only => [:create, :destroy]
end
...
And see your routing:
$ bundle exec rake routes accounts_numbers POST /accounts/numbers(.:format) accounts/numbers#create accounts_numbers DELETE /accounts/numbers/:id(.:format) accounts/numbers#destroy
Rails namespace by default use :path, :module and :as
# config/routes.rb
...
namespace :accounts do
resources :numbers, :only => [:create, :destroy]
end
...
I was surprised when I saw Postage for developers. Looks similar to stripe payments. I’m thinking about new startups “for developers” with exactly the same box which shows curl command and how easy it’s. Food for developers sounds good. Every team could be subscribe a food.
curl https://www.getfoodeasy.com/api/order \ -u cueqNZUb3ldeWTNX7MU3Mel8UXtaAMUi: \ -d 'company[name]=Apptamers' \ -d 'address[street1]=388 Townsend St' \ -d 'address[street2]=Apt 20' \ -d 'address[zip]=94107' \ -d 'order[position][]=Pizza'
Rails 4 has ActiveModel::Model. In rails 3 you can use combination of ActiveModel::Validations, ActiveModel::Conversion and ActiveModel::Naming
class TextMessage
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :from, :to, :body
validates :from, :presence => true
validates :to, :presence => true
validates :body, :presence => true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
When your page navigation has set fixed position like apptamers page, then you need to implement scroll to correct scroll down. Nice solution in jquery here:
$('a[href^="#"]').live('click',function(event){
event.preventDefault();
var offset = $(this.hash).offset() ? $(this.hash).offset().top : 0;
var scrollTop = offset - 150;
$('html, body').animate({ scrollTop: scrollTop }, 300);
});