Easy Ruby on Rails install

Whenever I setup new Linux for developing rails application. I feel bit tired of installing all necessary things for rails development.

For that I have written one shell script, that install most of the things requires for rails development. If you want this lazy thing. You can check here

https://github.com/navinspm/easy_rails

And use it , fork the code and update if you feel some thing to be added.

Thanks.

Advertisements

A simple instruction to Rspec – 3 in Ruby on Rails -4

This is small introduction about rspec version 3 for ruby on rails developers, and also note that this is not mean for techy geeks ­čÖé

Initial Setup
add gem 'rspec-rails', '~> 3.0.0'

then bundle install

And run rails generator rspec:install

Herein after spec files are automatically created when ever you create model, controller, view files, if you dont want any spec file to be created automatically then
in your application.rb

config.generators do |g|
g.test_framework :rspec,
view_specs: false,
helper_specs: false,
routing_specs: false,
controller_specs: true,
request_specs: false
end

put false wherever you dont want to create spec files
RSpec generators can also be run independently. For instance,

rails generate rspec:model post

All specs are created inside spec folder and to run test just type rspec in terminal

If you want to test only a particular file say products.rb in model then

 rspec ../rails_app/spec/models/products.rb

Thats all

Model specs

Examples
require "rails_helper"

describe Post do
it “checks it saves the data” do
expect(Post.count).to eq 0
@post=Post.create
@post.save
expect(Post.count).to eq 1
end
end

controller spec

require 'rails_helper'

RSpec.describe WelcomeController, :type => :controller do
it ‘has 300 status code’ do
get :index
expect(response.status).to eq(200)
end
end

Matchers

rspec-rails offers a number of custom matchers, most of which are
rspec-compatible wrappers for Rails’ assertions.

redirects
expect(response).to redirect_to(path)
templates
expect(response).to render_template(template_name)
assigned objects
expect(assigns(:widget)).to be_a_new(Widget)

Gemmified version of jquery plug-in stick

Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible .This is gemmified version of sticky

jQuery sticky 1.0.0 – http://stickyjs.com/

Installation

Add this line to your application’s Gemfile:

gem 'sticky-rails'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install sticky-rails

Usage

Sticky is a jQuery plugin that gives you the ability to make any element on your page always stay visible. , so please check if you are using the jquery on your rails app

//= require jquery

Your app/assets/javascripts/application.js must appear like:

//= require jquery
//= require jquery_ujs
//= require jquery.sticky.js
//= require_tree .

Basic Structure example from http://stickyjs.com/

<script>
  $(document).ready(function(){
    $("#sticker").sticky({topSpacing:0});
  });
</script> 

REMEMBER TO INITIALIZE IT!

If you are going to use coffee script:

$(document).ready ->
  $("sticker").sticky()

Or just javascript:

 $(document).ready(function(){
    $("#sticker").sticky({topSpacing:0});
  });

For more documentation please checkout the sticky-rails 4 repository here: https://github.com/garand/sticky

Gem Author

http://twitter.com/navinspm