Class: PolylingoChat::ConversationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PolylingoChat::ConversationsController
- Defined in:
- lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /polylingo_chat/conversations.
-
#destroy ⇒ Object
DELETE /polylingo_chat/conversations/:id.
-
#index ⇒ Object
GET /polylingo_chat/conversations.
-
#show ⇒ Object
GET /polylingo_chat/conversations/:id.
-
#update ⇒ Object
PATCH/PUT /polylingo_chat/conversations/:id.
Instance Method Details
#create ⇒ Object
POST /polylingo_chat/conversations
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb', line 24 def create @conversation = Conversation.new(conversation_params) if @conversation.save # Add participants if provided if params[:participant_ids].present? add_participants_from_params(@conversation) end respond_to do |format| format.html { redirect_to polylingo_chat_conversation_path(@conversation), notice: 'Conversation created successfully.' } format.json { render json: conversation_json(@conversation), status: :created } end else respond_to do |format| format.html { render :new, status: :unprocessable_entity } format.json { render json: { errors: @conversation.errors. }, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /polylingo_chat/conversations/:id
61 62 63 64 65 66 67 68 |
# File 'lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb', line 61 def destroy @conversation.destroy respond_to do |format| format.html { redirect_to polylingo_chat_conversations_path, notice: 'Conversation deleted successfully.' } format.json { head :no_content } end end |
#index ⇒ Object
GET /polylingo_chat/conversations
6 7 8 9 10 11 12 13 |
# File 'lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb', line 6 def index @conversations = Conversation.all.includes(:participants, :messages) respond_to do |format| format.html # renders app/views/polylingo_chat/conversations/index.html.erb format.json { render json: @conversations.map { |c| conversation_json(c) } } end end |
#show ⇒ Object
GET /polylingo_chat/conversations/:id
16 17 18 19 20 21 |
# File 'lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb', line 16 def show respond_to do |format| format.html # renders app/views/polylingo_chat/conversations/show.html.erb format.json { render json: conversation_json(@conversation, include_messages: true) } end end |
#update ⇒ Object
PATCH/PUT /polylingo_chat/conversations/:id
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/polylingo_chat/install/templates/controllers/polylingo_chat/conversations_controller.rb', line 46 def update if @conversation.update(conversation_params) respond_to do |format| format.html { redirect_to polylingo_chat_conversation_path(@conversation), notice: 'Conversation updated successfully.' } format.json { render json: conversation_json(@conversation) } end else respond_to do |format| format.html { render :edit, status: :unprocessable_entity } format.json { render json: { errors: @conversation.errors. }, status: :unprocessable_entity } end end end |