$ rails g model User
belongs_to
has_one
| class UsersController < ApplicationController | |
| respond_to :html, :json | |
| def index | |
| @json = User.all.to_gmaps4rails | |
| respond_with @json | |
| end | |
| end |
| var cat = {}; | |
| /** | |
| * cat.NewsBox | |
| * Retrieves news from Google | |
| */ | |
| cat.NewsBox = (function(){ | |
| function NewsBox(searchTerm, injectFn) { | |
| this.searchTerm = searchTerm; |
| <!DOCTYPE html> | |
| <script src="url.js"></script> | |
| <script> | |
| var url = new URL('http://www.example.com/a/b/c.html?p=q&r=s&p&p=t#hash'); | |
| for (var key in url) { | |
| console.log(key, url[key]); | |
| } |
NOTE I now use the conventions detailed in the SUIT framework
Used to provide structural templates.
Pattern
t-template-name
| /* | |
| You can now create a spinner using any of the variants below: | |
| $("#el").spin(); // Produces default Spinner using the text color of #el. | |
| $("#el").spin("small"); // Produces a 'small' Spinner using the text color of #el. | |
| $("#el").spin("large", "white"); // Produces a 'large' Spinner in white (or any valid CSS color). | |
| $("#el").spin({ ... }); // Produces a Spinner using your custom settings. | |
| $("#el").spin(false); // Kills the spinner. |
| var pubsub = {}; | |
| (function(q) { | |
| var topics = {}, subUid = -1; | |
| q.subscribe = function(topic, func) { | |
| if (!topics[topic]) { | |
| topics[topic] = []; | |
| } | |
| var token = (++subUid).toString(); | |
| topics[topic].push({ | |
| token: token, |
| Hi David, | |
| I came across your profile online and wanted to reach out about Development | |
| Opportunities here at Groupon. The company is growing, and we're always | |
| looking for folks with solid skills that can make positive contribution to | |
| our continued success. Any chance you'd be open to a quick conversation | |
| about opportunities, or for any possible networking potential? If so, let me | |
| know when you're free and we can set up a time to chat. Also, if you are | |
| interested, it would be great if you could forward a current resume over | |
| that I can take a look at. I look forward to hearing back from you! Please | |
| let me know if you have any questions. |
| class Api::RegistrationsController < Api::BaseController | |
| respond_to :json | |
| def create | |
| user = User.new(params[:user]) | |
| if user.save | |
| render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201 | |
| return | |
| else |
By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:
/people/6
But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.