This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb | |
class AddAuthenticationTokenToUsers < ActiveRecord::Migration | |
def change | |
add_column :users, :authentication_token, :string | |
add_index :users, :authentication_token, :unique => true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/models/user.rb | |
class User < ActiveRecord::Base | |
has_one :account_setting, :dependent => :destroy | |
accepts_nested_attributes_for :account_setting | |
end | |
# /app/controllers/users_controller.rb | |
class UsersController < ApplicationController | |
def new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/models/user.rb | |
class User < ActiveRecord::Base | |
has_one :account_setting, :dependent => :destroy | |
end | |
# /app/controllers/users_controller.rb | |
class UsersController < ApplicationController | |
def create | |
@user = User.new(params[:user]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
def edit | |
@post = get_post(params[:id]) | |
# ... | |
end | |
def update | |
@post = get_post(params[:id]) | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
before_filter :get_post, :only => [:edit, :update, :destroy] | |
def edit | |
# ... | |
end | |
def update | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
before_filter :get_post, :only => [:edit, :update, :destroy] | |
def get_post | |
@post = Post.find(params[:id]) | |
end | |
def edit | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/controllers/posts_controller.rb | |
class PostsController < ApplicationController | |
def edit | |
@post = Post.find(params[:id]) | |
# ... | |
end | |
def update | |
@post = Post.find(params[:id]) | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
current_user.posts.create( | |
:title => "This is the title", | |
:content => "This is the content of post" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/controllers/posts_controller.rb | |
p = Post.new | |
p.title = "This is the title" | |
p.content = "This is the content of post" | |
p.user = current_user | |
p.save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /app/models/topic.rb | |
class Topic < ActiveRecord::Base | |
scope :trending, lambda { |num = nil| where('started_trending > ?', 1.day.ago). | |
order('mentions desc'). | |
limit(num) } | |
# ... | |
end |