Giter Site home page Giter Site logo

foundation-apps-rails's Introduction

foundation-apps-rails

A Ruby on Rails starting app that integrates Foundation for Apps http://foundation.zurb.com/apps

Requirements

  • Node
  • Bower

Install

  • run the following commands to install bower components and node packages

bundle install
rake zfapp:install

  • run Gulp from the root directory to build the necessary javascript files, partials, templates, and iconic images. This will also watch for template changes.

gulp

Updating Foundation for Apps

  • simply run bower update from the root directory

Templates

  • front matter templates can be created in the directory app/views/templates
<!-- app/views/templates/example.html -->
---
name: Example
url: /example
---

<h1>Example</h1>

Angular

  • create angular assets under the directory app/assets/javascripts/angular/
// app/assets/javascripts/angular/controllers/example_controller.js
app.controller('ExampleController', ['$scope', function($scope) {
  $scope.hola = 'Hola';
}]);

Testing

  • Karma is used for testing and can be run with the following command (The rails server must be running at localhost:3000): rake karma:run (single run) or rake karma:start

  • Test files can be created in the directory spec/javascripts/angular/.

// spec/javascripts/angular/controllers/example_controller_spec.js
describe('ExampleController', function(){
  var $scope;

  beforeEach(module('application'));

  beforeEach(inject(function($rootScope, $controller) {
    $scope = $rootScope.$new();
    $controller('ExampleController', {$scope: $scope});
  }));

  it('should say Hola', function() {
    expect($scope.hola).toBe('Hola');
  });
});

Integrating with Rails

# posts_controller.rb

class PostsController < ApplicationController
  respond_to :json
  def index
    respond_with Post.all
  end
  
  # ...
  
end
  • api routes are under the api scope
scope :api, defaults: {format: :json} do
  resources :posts, except: [:new, :edit]
end

#     posts GET    /api/posts(.:format)          posts#index {:format=>:json}
#           POST   /api/posts(.:format)          posts#create {:format=>:json}
#      post GET    /api/posts/:id(.:format)      posts#show {:format=>:json}
#           PATCH  /api/posts/:id(.:format)      posts#update {:format=>:json}
#           PUT    /api/posts/:id(.:format)      posts#update {:format=>:json}
#           DELETE /api/posts/:id(.:format)      posts#destroy {:format=>:json}
  • an angular REST api service has been created to easily implement requests in a similar manner to rails development and allows for the following methods: getIndex() getShow(id) postCreate(params) putUpdate(params) deleteDestroy(params)
// app/assets/controllers/posts_controller.js
controllers.controller('Postscontroller', ['$scope', 'restApi', function($scope, restApi) {
  $scope.api = new restApi('posts');
  
  $scope.api.getIndex().then(function() {
    $scope.posts = $scope.api.data; // returns all posts
  });
}]);
<!-- app/views/templates/posts.html -->
---
name: posts
url: /posts
controller: PostsController
---
<div ng-repeat="post in posts">
  <h1>{{post.title}}</h1>
  <p>{{post.content}}</p>
</div>

foundation-apps-rails's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.