Skip to content

Instantly share code, notes, and snippets.

View VitorRibeiroCustodio's full-sized avatar
🏠
Working from home

Vitor Ribeiro VitorRibeiroCustodio

🏠
Working from home
  • Brasilia, Brazil
View GitHub Profile
import React from 'react';
import {Editor, EditorState} from 'draft-js';
import 'draft-js/dist/Draft.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {editorState: EditorState.createEmpty()};
this.onChange = editorState => this.setState({editorState});
}
before_action :set_post
def create
@post.comments.create! comments_params
redirect_to @post
end
def set_post
@post = Post.find(params[:post_id])
end
def comments_params
params.required(:comment).permit(:body)
<%= form_for([@post, Comment.new], remote: true) do |form| %>
Your comment: <br>
<%= form.text_area :body, size: '50x20' %><br>
<%= form.submit %>
<% end %>
<p><%= comment.body %> -- <%= comment.created_at.to_s(:long) %> </p>
<br><br>
<h3>Comments</h3>
<div>
<%= render @post.comments %>
</div>
<%= render 'comments/new', post: @post %>
Rails.application.routes.draw do
resources :posts do
resources :comments
end
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
class Post < ApplicationRecord
has_many :comments

validates_presence_of :title

end
class Post < ApplicationRecord

validates_presence_of :title

end