mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23401 from claudiob/fix-as-changelog-md
[ci skip] Properly indent code in markdown
This commit is contained in:
commit
9aa425f75f
1 changed files with 32 additions and 32 deletions
|
@ -42,44 +42,44 @@
|
|||
Here's an example of a simple event tracking system where the object being tracked needs not pass a creator that it
|
||||
doesn't need itself along:
|
||||
|
||||
module Current
|
||||
thread_mattr_accessor :account
|
||||
thread_mattr_accessor :user
|
||||
module Current
|
||||
thread_mattr_accessor :account
|
||||
thread_mattr_accessor :user
|
||||
|
||||
def self.reset() self.account = self.user = nil end
|
||||
end
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :set_current
|
||||
after_action { Current.reset }
|
||||
|
||||
private
|
||||
def set_current
|
||||
Current.account = Account.find(params[:account_id])
|
||||
Current.user = Current.account.users.find(params[:user_id])
|
||||
def self.reset() self.account = self.user = nil end
|
||||
end
|
||||
end
|
||||
|
||||
class MessagesController < ApplicationController
|
||||
def create
|
||||
@message = Message.create!(message_params)
|
||||
end
|
||||
end
|
||||
class ApplicationController < ActionController::Base
|
||||
before_action :set_current
|
||||
after_action { Current.reset }
|
||||
|
||||
class Message < ApplicationRecord
|
||||
has_many :events
|
||||
after_create :track_created
|
||||
|
||||
private
|
||||
def track_created
|
||||
events.create! origin: self, action: :create
|
||||
private
|
||||
def set_current
|
||||
Current.account = Account.find(params[:account_id])
|
||||
Current.user = Current.account.users.find(params[:user_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Event < ApplicationRecord
|
||||
belongs_to :creator, class_name: 'User'
|
||||
before_validation { self.creator ||= Current.user }
|
||||
end
|
||||
class MessagesController < ApplicationController
|
||||
def create
|
||||
@message = Message.create!(message_params)
|
||||
end
|
||||
end
|
||||
|
||||
class Message < ApplicationRecord
|
||||
has_many :events
|
||||
after_create :track_created
|
||||
|
||||
private
|
||||
def track_created
|
||||
events.create! origin: self, action: :create
|
||||
end
|
||||
end
|
||||
|
||||
class Event < ApplicationRecord
|
||||
belongs_to :creator, class_name: 'User'
|
||||
before_validation { self.creator ||= Current.user }
|
||||
end
|
||||
|
||||
*DHH*
|
||||
|
||||
|
|
Loading…
Reference in a new issue