Reputation: 1
I do chat on action cable. And I have a problem with post view. However, in order to show a message from a user, it additionally outputs the entire hash of all messages in this chat. This what i get: chan with extra json
When i use developer tools in chrome i saw it block without any selector or style. I can delete it in tools but can't remove it in view. My post controller:
def index
@posts = Post.all
end
def show
@post = Post.find(params[:id])
end
def create
@post = Post.new(post_params)
@post.customer = current_customer
@post.save
redirect_to request.referrer
SendMessageJob.perform_later(@post)
end
rooms index.html.haml
#room-id{"data-room-id" => @room.try(:id)}
#customer-id{"data-customer-id" => current_customer.id}
.container-fluid
.row
.col-3.rooms-sidebar
%b Создать новое объявление
= render 'form', room: Room.new
%hr
- @rooms.each do |room|
.room-link
= link_to room do
.card.mb-2.room-card
.card-body
%span.name
= room.name
= link_to 'Delete', room, method: :delete, data: { confirm:
'Are you sure?' }
.col-9
- if @room.present?
.chat-room
= @room.name
= image_tag @room.image.url(:thumb), class: 'img-show' if @room.image?
#messages
= @room.posts.each do |post|
= render 'posts/post', post: post
.chat-box
= render 'posts/form', post: Post.new, room: @room
my db schema
create_table "rooms", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "image"
t.string "content"
end
create_table "posts", force: :cascade do |t|
t.text "title"
t.text "content"
t.bigint "customer_id", null: false
t.bigint "room_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["customer_id"], name: "index_posts_on_customer_id"
t.index ["room_id"], name: "index_posts_on_room_id"
end
posts/_form.html.haml
= form_with(model: post, local: true) do |f|
- if @post && @post.errors.any?
#error_explanation
%h2= "#{pluralize(@post.errors.count, "error")} prohibited this post from
being saved:"
%ul
- @post.errors.full_messages.each do |message|
%li= message
.field
= f.hidden_field :room_id, value: room.id
.input-group
= f.text_area :content, placeholder: 'Type your message...', class:
'form-control', style: 'width: 100%'
.actions
= f.submit 'Send message', class: 'btn btn-primary', style: 'width: 100%'
I don't understand where the extra json comes from below and how to get rid of it.
Upvotes: 0
Views: 37
Reputation: 4558
Change = @room.posts.each do |post|
to - @room.posts.each do |post|
. The json result comes from the each
.
Upvotes: 0