Как реализовать удаленную форму для другого действия контроллера в Rails 5 без перенаправления? - PullRequest
0 голосов
/ 23 марта 2019

Попытка отправить форму, которая имеет действие создания в другом контроллере, но не перенаправляет или не отображает страницу (просто остается на странице).

Ошибка:

MessagesController#create is missing a template for this request format and variant. request.formats: ["text/html"] request.variant: []

Форма (rooms / show.html.haml):

  = form_for [@room, Message.new], remote: true do |f| 
    .field
      = f.text_field :body, placeholder: "Message #{@room.name}", autofocus: true

Действие удаленного контроллера:

class MessagesController < ApplicationController
  skip_before_action :verify_authenticity_token
  before_action :authenticate_user!
  before_action :set_room

  def create
    message = @room.messages.new(message_params)
    message.user = current_user
    message.save
    MessageRelayJob.perform_later(message)
  end

  private

    def set_room
      @room = current_user.rooms.find(params[:room_id])
    end

    def message_params
      params.require(:message).permit(:body)
    end
end

messages / create.js.erb

$("#new_message")[0].reset();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...