2017-01-23 3 views
0

채팅 응용 프로그램에서 이미지를 첨부하고 싶습니다. 텍스트 채팅으로 작업을했는데 actioncable로 첨부 파일을 보낼 수 없습니다.첨부 파일이있는 ActionCable

App.global_chat = App.cable.subscriptions.create { 
     channel: "ChatRoomsChannel" 
     chat_room_id: messages.data('chat-room-id') 
     }, 
     connected: -> 
     # Called when the subscription is ready for use on the server 

     disconnected: -> 
     # Called when the subscription has been terminated by the server 

     received: (data) -> 
     messages.append data['message'] 
     messages.append data['attachment'] 
     messages_to_bottom() 

     send_message: (message, chat_room_id, attachment) -> 
     @perform 'send_message', message: message, chat_room_id: chat_room_id, attachment: attachment 

    $('#new_message').submit (e) -> 
     $this = $(this) 
     textarea = $this.find('#message_body') 
     attachment = $this.find('#message_attachment') 
     if $.trim(textarea.val()).length > 1 
     App.global_chat.send_message textarea.val(), messages.data('chat-room-id'), attachment[0].files[0] 
     textarea.val('') 
     attachment.val('') 
     e.preventDefault() 
     return false 

답변

0

나는 의견을 말할 수는 없지만 그것을 달성하기위한 조언을 줄 수 있습니다.

아시다시피 form_for의 레일은 아약스 업로드를 지원하지 않으며 아약스 업로드의 레일은 너무 어려워서 너무 깊게 파고 들었습니다.

첫 번째는 파일 입력과 양식을 만들 수있는 보석을 추가 한 후이 보석

gem 'remotipart', '~> 1.2' 

를 설치합니다. 가장 좋은 점은 파일을 자동으로 업로드하는 보석을 추가 한 후입니다. 양식을 만드는 동안 remote: trueform_for에 추가하십시오.

나는 종이 클립 보석으로 시도했으며 완벽하게 작동합니다. 문제가 있으면 핑 (Ping)