Open yuyanegishi opened 5 years ago
@micropost = current_user.microposts.build(micropost_params)
def current_user
if session[:user_id]
@current_user ||= User.find_by(id: session[:user_id])
end
end
build(attributes = nil, &block)
Alias for: new
new(attributes = nil, &block)
Initializes new record from relation while maintaining the current scope.
Expects arguments in the same format as ActiveRecord::Base.new.