Apptamers

« Apptamers Site

  • rss
  • archive
  • rails rspec tests generator

      # config/environments/development.rb
      config.generators do |g|
        g.test_framework :rspec
      end
    

    • 2 days ago
  • Rails params required/permit. Mass assigment. Strong parameters

    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


    https://github.com/rails/strong_parameters

    • 3 weeks ago
  • mongoid clone embedded document

    its = model.clone
    

    • 1 month ago
  • forgery gem and random sentences

    Forgery(:lorem_ipsum).sentences(3, :random => true)
    

    • 1 month ago
  • Undefined mixin ‘ie7-inline-block’.

    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";
    
    • 1 month ago
  • Rails helper block capture

    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
    
    • 1 month ago
  • Rails 3 routes scope vs namespace

    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
    ...
    
    • 1 month ago
  • Postage for developers

    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'
    
    • 1 month ago
  • Rails model without table

    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
    
    • 1 month ago
  • Scroll page when navigation/header has fixed position set

    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);
    });
    
    • 1 month ago
© 2012–2013 Blog | Apptamers
Next page
  • Page 1 / 4