야드로 문서를 생성하고 있지만 레일즈 프로젝트에서 루비에 대한 예제 문서를 찾을 수 없습니다. 나는 단지 getting started tutorial이라는 짧은 글과 rubydoc.info의 일부 github 프로젝트를 발견했지만, 그들은 전혀 문서화되지 않았다.문서 야드로 레일스 프로젝트
class ArticlesController < ApplicationController
before_filter :authenticate_user!, except: [:show]
before_filter :restrict_user, only: [:edit, :update]
def index
@articles = current_user.articles.sort_by_rating.
paginate(:page => params[:page],
per_page: 5)
end
def new
@user = User.find(params[:user_id])
@article = @user.articles.build
end
def create
@user = User.find(params[:user_id])
@article = @user.articles.build(params[:article])
if @article.save
redirect_to @article, notice: 'Article was successfully created.'
else
render action: "new"
end
end
end
그리고 사용자 모델 :
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable :recoverable
devise :database_authenticatable, :registerable,
:rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
# attr_accessible :title, :body
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
has_many :articles, dependent: :destroy
letsrate_rater
end
무엇을하려하십니까? – Benjamin
방금 귀하 또는 다른 사람들에게 도움이 될 수있는 질문에 대한 답변을 추가했습니다. – engineersmnky