Class: Lesli::Items::DiscussionsController

Inherits:
ApplicationLesliController show all
Defined in:
app/controllers/lesli/items/discussions_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#engine_path, #query

Instance Method Summary collapse

Methods inherited from ApplicationLesliController

#log

Methods included from CustomizationInterface

#set_customizer

Methods included from ResponderInterface

#respond_with_action, #respond_with_http, #respond_with_json, #respond_with_json_not_found, #respond_with_json_unauthorized, #respond_with_lesli, #respond_with_not_found, #respond_with_pagination, #respond_with_unauthorized, #stream_redirection

Methods included from RequesterInterface

#set_locale, #set_requester

Methods inherited from ApplicationController

#initialize

Constructor Details

This class inherits a constructor from Lesli::ApplicationController

Instance Method Details

#createObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/lesli/items/discussions_controller.rb', line 49

def create
    discussion = discussion_class.new(discussion_params)

    discussion.user = current_user
    discussion. = current_user.
    discussion.discussable = @discussable if @discussable

    if discussion.save
        respond_with_lesli(:turbo => [
            stream_notification_success("Discussion created"),
            turbo_stream.prepend("#{scope_key}-lesli-items-discussions-list") do
                LesliView::Items::Discussion.new(discussion).render_in(view_context)
            end
        ])
    else
        respond_with_lesli(
            :turbo => stream_notification_danger(discussion.errors.full_messages)
        )
    end
end

#indexObject



39
40
41
42
43
44
# File 'app/controllers/lesli/items/discussions_controller.rb', line 39

def index
    @discussions = discussion_class
        .where(account: current_user.)
        .order(created_at: :desc)
    respond_with_lesli(json: @discussions)
end

#showObject



46
47
# File 'app/controllers/lesli/items/discussions_controller.rb', line 46

def show
end

#updateObject



70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/lesli/items/discussions_controller.rb', line 70

def update
    @discussion.done = true
    @discussion.save
    respond_with_lesli(:turbo => [
        stream_notification_success("Discussion updated #{@discussable}"),
        turbo_stream.replace(helpers.dom_id(@discussion, scope_key)) do 
            LesliView::Items::Discussion.new(@discussion, scope_key).render_in(view_context)
        end
    ])
end