Zusammenfassung der Ressource
Wiki App
- Users
- data Model
- Devise
- :confirmable
- :database_authenticatable
- :registerable
- :recoverable
- :rememberable
- :trackable
- :validatable
- have and belong to many wikis (through collaborators)
- validates :username (string), presence: true
- id (integer)
- app/models/user.rb
- def collaborators: Collaborator.where(user_id: id)
- def wikis: collaborators.wikis
- Controller
- View
- Wikis
- data Model
- default_scope { order(:title ASC' }
- validates :body (string/markdown), presence: true
- validates :private (boolean), presence: true
- default t.boolean :private
- validates :title (string), presence: true
- id (integer)
- has many users through collaborators
- app/models/wiki.rb
- has_many :collaborators
- def users: collaborators.users
- delegate :users, to: collaborators
- belongs to user (user that created it)
- Controller
- index, show, new, create, destroy
- private: def wiki_params
- View
- Private wikis
- visible to: admins, @wiki.user, @wiki.collaborator
- Public wikis
- visible to: everyone
- Application Controller
- before_action :authenticate_user!
- Collaborators
- data Model
- user_id (integer)
- wiki_id (integer)
- id (integer)
- app/models/collaborator.rb
- def self.wikis: Wiki.where( id: pluck(:wiki_id) )
- def self.users: User.where( id: pluck(:user_id) )
- def wiki: Wiki.find(wiki_id)
- def user: User.find(user_id)