This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_for([@post, Comment.new], remote: true) do |form| %> | |
Your comment: <br> | |
<%= form.text_area :body, size: '50x20' %><br> | |
<%= form.submit %> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p><%= comment.body %> -- <%= comment.created_at.to_s(:long) %> </p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<br><br> | |
<h3>Comments</h3> | |
<div> | |
<%= render @post.comments %> | |
</div> | |
<%= render 'comments/new', post: @post %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ApplicationRecord | |
has_many :comments | |
validates_presence_of :title | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post < ApplicationRecord | |
validates_presence_of :title | |
end |