Code Monkey home page Code Monkey logo

angular-rails-book's Introduction

Getting Started with Angular on Ruby on Rails

This is the source of http://angular-rails.com. To build it, you'll need to do a few things:

  1. bundle install or gem install bookingit to install the bookingit gem
  2. git clone https://github.com/davetron5000/receta git_repos/receta to clone the repository containing the source code examples in the book
  3. createuser -d receta to create a new PostgreSQL user as required by receta/config/database.yml
  4. pushd git_repos/receta && bundle install && popd to install all gems that are required for the receta project
  5. bookingit build to generate the HTML and CSS for the book

Once this is done, open book/index.html in your browser. Whenever you change something, re-run bookingit build.

Changes to the source

bookingit uses git tags and such to generate the source and diffs in the book. This allows me to know that everything is working and control what's being displayed. Unfortunately, if something needs to change, this breaks all the tags and SHA-1s. I haven't sorted out a good way to fix this yet.

angular-rails-book's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-rails-book's Issues

Remind reader to add newRecipe() function to the RecipesController

Hello!

First: thank you so much for the excellent tutorial!

Now the issue: I think it should be mentioned in the section 4.3 (crud_recipe.md) that the reader has to add the newRecipe() function to the RecipesController (it's got called by click on the New Recipe... button).

$scope.newRecipe = -> $location.path("/recipes/new")

how to add services/factories

Couldn't find another way to ask this question. Wondering how you would add a factory (to use $resource for instance) as a separate file? Would be great to extend the book to address how you would add a service for accessing restful backend services rather than include the $resource in the controller.

Thanks for your work!

ActionView::Template::Error: Missing partial

In step 2.3, "Tests", my tests are failing with the following output when I run

rake db:migrate RAILS_ENV=test ; rspec spec/controllers/recipes_controller_spec.rb

[20:12:25] (master) receta
// ♥ rake db:migrate RAILS_ENV=test ; rspec spec/controllers/recipes_controller_spec.rb
.FFFF

Failures:

  1) RecipesController index when the search finds results should include 'Baked Brussel Sprouts'
     Failure/Error: xhr :get, :index, format: :json, keywords: keywords
     ActionView::Template::Error:
       Missing partial recipes/_recipe, application/_recipe with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:jbuilder]}. Searched in:
         * "/Users/Dan/work/angular-rails/receta/app/views"
     # ./app/views/recipes/index.json.jbuilder:1:in `_app_views_recipes_index_json_jbuilder___2543389150451662351_70112294416720'
     # ./spec/controllers/recipes_controller_spec.rb:12:in `block (3 levels) in <top (required)>'

  2) RecipesController index when the search finds results should return two results
     Failure/Error: xhr :get, :index, format: :json, keywords: keywords
     ActionView::Template::Error:
       Missing partial recipes/_recipe, application/_recipe with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:jbuilder]}. Searched in:
         * "/Users/Dan/work/angular-rails/receta/app/views"
     # ./app/views/recipes/index.json.jbuilder:1:in `_app_views_recipes_index_json_jbuilder___2543389150451662351_70112294416720'
     # ./spec/controllers/recipes_controller_spec.rb:12:in `block (3 levels) in <top (required)>'

  3) RecipesController index when the search finds results should include 'Baked Potato w/ Cheese'
     Failure/Error: xhr :get, :index, format: :json, keywords: keywords
     ActionView::Template::Error:
       Missing partial recipes/_recipe, application/_recipe with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:jbuilder]}. Searched in:
         * "/Users/Dan/work/angular-rails/receta/app/views"
     # ./app/views/recipes/index.json.jbuilder:1:in `_app_views_recipes_index_json_jbuilder___2543389150451662351_70112294416720'
     # ./spec/controllers/recipes_controller_spec.rb:12:in `block (3 levels) in <top (required)>'

  4) RecipesController index when the search finds results should 200
     Failure/Error: xhr :get, :index, format: :json, keywords: keywords
     ActionView::Template::Error:
       Missing partial recipes/_recipe, application/_recipe with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:jbuilder]}. Searched in:
         * "/Users/Dan/work/angular-rails/receta/app/views"
     # ./app/views/recipes/index.json.jbuilder:1:in `_app_views_recipes_index_json_jbuilder___2543389150451662351_70112294416720'
     # ./spec/controllers/recipes_controller_spec.rb:12:in `block (3 levels) in <top (required)>'

Finished in 0.33643 seconds
5 examples, 4 failures

Failed examples:

rspec ./spec/controllers/recipes_controller_spec.rb:32 # RecipesController index when the search finds results should include 'Baked Brussel Sprouts'
rspec ./spec/controllers/recipes_controller_spec.rb:26 # RecipesController index when the search finds results should return two results
rspec ./spec/controllers/recipes_controller_spec.rb:29 # RecipesController index when the search finds results should include 'Baked Potato w/ Cheese'
rspec ./spec/controllers/recipes_controller_spec.rb:23 # RecipesController index when the search finds results should 200

Randomized with seed 53057

How does Back button retain previous search?

[Couldn't find a way to contact you directly; hope it's OK that I ask this here. If I had this question, other readers might too.]

Thanks for your book; this was a really helpful introduction to AngularJS with RoR. When I was all done, there was just one thing that puzzled me. The 'Back' button is defined as:

<button ng-click="back()" class="btn btn-default">

and clicking that calls the back() function in RecipeController which looks like this:

$scope.back   = -> $location.path("/")

The behavior you see in the browser (and that the specs validate is happening) is that when you click 'Back' you not only return to the root path, but the keywords you used in the previous search are still there. To achieve this I would have expected something like:

$scope.back   = -> $location.path("/").search('keywords', keywords)

as it's done in RecipesController. Is there some magic about $location.path(...) that preserves whatever URL parameters there were before, or is there something else that accomplishes it? What would you do if you wanted a link/button that took you to the root path and cleared any previous keywords?

Trouble Loading Bootstrap Icons

Not sure what has changed since when you lasted updated but following the instructions for setting up bootstrap using bower doesn't appear to be playing nicely. I can load the bootstrap stylesheets, but the fonts are causing trouble.

The issue occurs when trying to @import "bootstrap-sass-official/assets/stylesheets/bootstrap-sprockets";

screen shot 2015-05-21 at 4 46 50 pm

I've read about this potentially being an issue with sprocket-rails but changing the gem version didn't fix it for me. rails/sprockets-rails#217

Here's my config/application.rb

config.assets.paths << Rails.root.join("lib","assets","bower_components")
config.assets.paths << Rails.root.join("lib","assets","bower_components","bootstrap-sass-official","assets","fonts")
config.assets.precompile << %r(.*.(?:eot|svg|ttf|woff)$)

Using Rails 4.2, Ruby 2.1.3

Skipping CSRF protection isn't required

I guess you should mention that CSRF protection can be enabled by a workaround. The average beginner might not be aware of the consequences of just deactivating this security feature.

stackoverflow has a pretty good workaround.

NoMethodError: undefined method `xhr'

This is happening in section 3.2 "Rails controller".

When I run rspec spec/controllers/recipes_controller_spec.rb, I get this:

// ♥ rspec spec/controllers/recipes_controller_spec.rb
FFFFF.....

Failures:

  1) show when the recipe exists 
     Failure/Error: xhr :get, :show, format: :json, id: recipe_id
     NoMethodError:
       undefined method `xhr' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fefb9ee3558>
     # ./app/controllers/recipes_controller.rb:12:in `block (2 levels) in <class:RecipesController>'

  2) show when the recipe exists 
     Failure/Error: xhr :get, :show, format: :json, id: recipe_id
     NoMethodError:
       undefined method `xhr' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fefb9e82aa0>
     # ./app/controllers/recipes_controller.rb:12:in `block (2 levels) in <class:RecipesController>'

  3) show when the recipe exists 
     Failure/Error: xhr :get, :show, format: :json, id: recipe_id
     NoMethodError:
       undefined method `xhr' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fefb9e69820>
     # ./app/controllers/recipes_controller.rb:12:in `block (2 levels) in <class:RecipesController>'

  4) show when the recipe exists 
     Failure/Error: xhr :get, :show, format: :json, id: recipe_id
     NoMethodError:
       undefined method `xhr' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007fefb9e50dc0>
     # ./app/controllers/recipes_controller.rb:12:in `block (2 levels) in <class:RecipesController>'

  5) show when the recipe doesn't exit 
     Failure/Error: xhr :get, :show, format: :json, id: recipe_id
     NoMethodError:
       undefined method `xhr' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_2:0x007fefbd972930>
     # ./app/controllers/recipes_controller.rb:12:in `block (2 levels) in <class:RecipesController>'

Finished in 0.43231 seconds
10 examples, 5 failures

Failed examples:

rspec ./app/controllers/recipes_controller.rb:24 # show when the recipe exists 
rspec ./app/controllers/recipes_controller.rb:27 # show when the recipe exists 
rspec ./app/controllers/recipes_controller.rb:25 # show when the recipe exists 
rspec ./app/controllers/recipes_controller.rb:26 # show when the recipe exists 
rspec ./app/controllers/recipes_controller.rb:32 # show when the recipe doesn't exit 

Randomized with seed 64006

My code is on github here

Bunch of random notes/corrections from a reader

  • #=> bower-rails is subtracted from gemfile .. should be added
  • #=> where goes the Bowerfile
    • newbies may not know where to put the Bowerfile since its not auto generated
  • #=> rake bower:install
  • Bower not found! You can install Bower using Node and npm:
    $ npm install bower -g
    • i had npm installed but not everyone might
  • => application.css differences

    • i dont know if this even matters but it looks like new rails switches self and tree .

      *= require_tree .
      *= require bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.css
      *= require_self

  • => remove turbolinks from these when removing turbolinks

    • rails server first run :

      <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
      <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>

  • #=> I had this error when starting the rails server at first:
    ActionView::Template::Error (couldn't find file 'bootstrap/glyphicons-halflings-regular.eot'
    (in /Users/jongutwillig/Rails/receta/vendor/assets/bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.scss:1)):
  • I got around this by commenting out vendor/assets/bower_components/bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.scss

//@import "bootstrap/glyphicons";

  • => coffee script comma question: note 'w/cheese' has no comma afterwards, the rest all do. i pulled all the commas - didnt seem to matter either way

    {
    id: 1
    name: 'Baked Potato w/ Cheese'
    },
    {
    id: 2
    name: 'Garlic Mashed Potatoes',
    },

  • => my rspec auto generated spec_helper file is a bit different -

    ActiveRecord::Migration.maintain_test_schema! - same thing really

  • => recipe #index typo ?

    • im running sqlite3 in dev because my homebrew is f'd up

    • if u wanna support sqlite3 - this is the fix

      • ilike -- error'd -- changed to like worked

      Recipe.where('name like ?',"%#{params[:keywords]}%")

  • => phantonjs complains at rake teaspoon

    add Rails.application.config.assets.precompile += %w( teaspoon.css ) to config/initializers/assets.rb and restart your server
    Rails.application.config.assets.precompile += %w( jasmine/1.3.1.js )toconfig/initializers/assets.rb` and restart your server

  • fixed with create initializers/assets.rb added code :

    Rails.application.config.assets.precompile += %w( teaspoon.css jasmine/1.3.1.js teaspoon-jasmine.js )

  • => these are the errors when i stopped:

    rake teaspoon errors :

    1. RecipesController encountered a declaration exception
      Failure/Error: ReferenceError: Can't find variable: module in http://127.0.0.1:57538/assets/controllers/RecipesController_spec.js?body=1 (line 22)

    if i set module = angular.module i get these errors

    1. RecipesController encountered a declaration exception
      Failure/Error: TypeError: 'undefined' is not a function (evaluating 'this.func.apply(this.spec)') in http://127.0.0.1:57682/assets/jasmine/1.3.1.js?body=1 (line 1066)

    2. RecipesController encountered a declaration exception
      Failure/Error: ReferenceError: Can't find variable: inject in http://127.0.0.1:57682/assets/controllers/RecipesController_spec.js?body=1 (line 21)

  • if i add this module = angular.module('receta') to vars in describe i get this error and change beforeEach(module) i get the same two errors above

undefined method 'configure' for Teaspoon:Module

This is happening in section 4.2 when I run rake teaspoon

// ♥ rake teaspoon
rake aborted!
NoMethodError: undefined method `configure' for Teaspoon:Module
/Users/Dan/work/angular-rails/receta/spec/teaspoon_env.rb:1:in `<top (required)>'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `block in require'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:274:in `require'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/environment.rb:40:in `require_env'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/environment.rb:23:in `block in require_environment'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/environment.rb:21:in `each'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/environment.rb:21:in `require_environment'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/environment.rb:7:in `load'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/teaspoon/console.rb:12:in `initialize'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/tasks/teaspoon.rake:5:in `new'
/Users/Dan/.rvm/gems/ruby-2.2.2/gems/teaspoon-0.7.9/lib/tasks/teaspoon.rake:5:in `block in <top (required)>'
Tasks: TOP => teaspoon
(See full trace by running task with --trace)

I get the problem with both the receta that I'm building and the finished one.

Bootstrap require path is now wrong

In the section titled "Creating a Skeleton App", when I installed bootstrap-sass-official, the path that I needed to reference it by was different that what you mention. Instead "bootstrap-sass-official/vendor/assets/stylesheets/bootstrap.css", the path I had to use was "bootstrap-sass-official/assets/stylesheets/bootstrap.css" (i.e. without the vendor). I also had to change your code accordingly any other place vendor was included in the path.

test is missing local var initialization

In the section titled "Building the First Feature", when you talk about injecting $httpBackend into the setupController method, you don't mention that above setupController, httpBackend needs to be initialized: "httpBackend = null".

Small issues?

rake db:setup was complaining about the migrations table not being there
I resolved by running rake db:create

I had to update the reference to bootstrap in stylesheets:

*= require bootstrap-sass-official/assets/stylesheets/_bootstrap

Setting up angular-rails-templates required adding to application.js:

//= require_tree ./templates

Basic gems out of date?

When I read the Basic Gems chapter, I notice it might be out of date?

Note that we're also pinning version 3.2.19 of the sass gem.

Looks like the receta master isn't pinning it.

Also, the Gemfile in master is very different from the small diff you're showing in the book. It might be better to point to the raw Gemfile in the repo? It will always be up to date.

I'd like to submit a PR for this, if you're cool with the changes.

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.