Module: Lesli::Interfaces::Controllers::Discussions
- Defined in:
- app/controllers/lesli/interfaces/controllers/discussions.rb
Instance Method Summary collapse
-
#create ⇒ Json
Json that contains wheter the creation of the discussion was successful or not.
-
#destroy ⇒ Json
A response that contains wheter the discussion was deleted or not.
-
#index ⇒ Json
Json that contains a list of all discussions related to a cloud_object.
-
#show ⇒ JSON
The json information about the selected discussion.
-
#update ⇒ Json
Json that contains wheter the update of the discussion was successful or not.
Instance Method Details
#create ⇒ Json
Returns Json that contains wheter the creation of the discussion was successful or not. If it is not successful, it returs an error message.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/controllers/lesli/interfaces/controllers/discussions.rb', line 98 def create discussion_model = discussion_model() # If there is a custom discussion model, it must be returned in this method cloud_object_model = discussion_model.cloud_object_model set_cloud_object new_discussion_params = { #"#{discussion_model.table_name}_id": discussion_params[:discussion_parent_id], content: discussion_params[:content], user_creator: current_user, cloud_object: @cloud_object } discussion = discussion_model.new(new_discussion_params) if discussion.save translations_path = @cloud_object.class.name.gsub("Cloud", "").underscore.pluralize.gsub("/", ".") cloud_object_class_translation = I18n.t("#{translations_path}.view_title_main") "#{cloud_object_model}::Subscriber".constantize.notify_subscribers( current_user, discussion.cloud_object, "discussion_created", subject: "#{cloud_object_class_translation} (#{@cloud_object.global_identifier}): #{I18n.t("core.shared.view_title_notification_discussions_created")}", body: "#{discussion.user_creator.full_name} #{I18n.t("core.shared.view_text_notification_discussion_created_body")}: '#{discussion.content}'", url: "/#{@cloud_object.class.name.split("::").last.pluralize.downcase}/#{@cloud_object.url_identifier}?tab=discussions" ) if Object.const_defined?("#{cloud_object_model}::Subscriber") if block_given? yield(cloud_object, discussion) else # Returning the 200 HTTP response respond_with_successful(discussion.show(current_user)) end else respond_with_error(discussion.errors.) end end |
#destroy ⇒ Json
Returns A response that contains wheter the discussion was deleted or not. If it is not successful, it returns an error message.
172 173 174 175 176 177 178 179 180 181 |
# File 'app/controllers/lesli/interfaces/controllers/discussions.rb', line 172 def destroy set_discussion return respond_with_not_found unless @discussion if @discussion.destroy respond_with_successful else respond_with_error(@discussion.errors..to_sentence) end end |
#index ⇒ Json
Returns Json that contains a list of all discussions related to a cloud_object.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/lesli/interfaces/controllers/discussions.rb', line 46 def index discussion_model = discussion_model() # If there is a custom discussion model, it must be returned in this method cloud_object_model = discussion_model.cloud_object_model @discussions = discussion_model.index( current_user, params["#{cloud_object_model.name.demodulize.underscore}_id".to_sym], @query ) if block_given? yield(@discussions) else #respond_with_successful(@discussions) respond_with_pagination(@discussions) end end |
#show ⇒ JSON
Returns The json information about the selected discussion.
72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/lesli/interfaces/controllers/discussions.rb', line 72 def show set_discussion return respond_with_not_found unless @discussion if block_given? yield(@discussion) else return respond_with_successful(@discussion) end end |
#update ⇒ Json
Returns Json that contains wheter the update of the discussion was successful or not. If it is not successful, it returs an error message.
152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/controllers/lesli/interfaces/controllers/discussions.rb', line 152 def update set_discussion return respond_with_not_found unless @discussion return unless @discussion.is_editable_by?(current_user) if @discussion.update(discussion_params) respond_with_successful else respond_with_error(@discussion.errors..to_sentence) end end |