Class: Pulitzer::PostsController::Update

Inherits:
Object
  • Object
show all
Includes:
Validations
Defined in:
app/interactions/pulitzer/posts_controller/update.rb

Instance Method Summary collapse

Methods included from Validations

#validate_title

Constructor Details

#initialize(post, params) ⇒ Update

Returns a new instance of Update.



4
5
6
# File 'app/interactions/pulitzer/posts_controller/update.rb', line 4

def initialize(post, params)
  @post, @params = post, params
end

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
# File 'app/interactions/pulitzer/posts_controller/update.rb', line 8

def call
  @post.assign_attributes @params
  if @post.changes.keys.map(&:to_sym).include?(:title)
    validate_title or return @post
    @post.slug = nil
  end
  @post.save
  @post
end