Created
September 13, 2015 00:29
-
-
Save rickywid/4ca5d1c417270bc1f1fa to your computer and use it in GitHub Desktop.
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 CommentsController < ApplicationController | |
def create | |
@movie = Movie.find(params[:id]) | |
@comment = @movie.comments.new(comment_params) | |
@comment.user = current_user | |
if @comment.save | |
redirect_to movie_path(@movie) | |
else | |
render 'show' | |
end | |
end | |
private | |
def comment_params | |
params.require(:comment).permit(:author_name, :body) | |
end | |
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 MoviesController < ApplicationController | |
def index | |
@movie = Movie.all | |
end | |
def new | |
@movie = Movie.new | |
end | |
def create | |
@movie = Movie.new(movie_params) | |
if @movie.save | |
flash[:success] = "Novie Added" | |
redirect_to @movie | |
else | |
render 'new' | |
end | |
end | |
def edit | |
@movie = Movie.find(params[:id]) | |
end | |
def update | |
@movie = Movie.find(params[:id]) | |
@movie.update(movie_params) | |
if @movie.save | |
flash[:success] = "Movie Updated" | |
redirect_to @movie | |
else | |
render 'edit' | |
end | |
end | |
def show | |
@movie = Movie.find(params[:id]) | |
end | |
def destroy | |
@movie = Movie.find(params[:id]) | |
@movie.destroy | |
flash[:success] = "Movie deleted" | |
redirect_to root_url | |
end | |
private | |
def movie_params | |
params.require(:movie).permit(:title, :description, :image) | |
end | |
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
.row | |
.col-md-3 | |
.panel.panel-default | |
.panel-body | |
= image_tag @movie.image.url(:medium) | |
%h1= @movie.title | |
%p= @movie.description | |
.btn-group | |
= link_to "Edit", edit_movie_path(@movie), class: "btn btn-default" | |
= link_to "Destroy", movie_path, method: :delete, class: "btn btn-default" | |
.col-md-9 | |
.panel.panel-default | |
.panel-heading | |
%h5 Comments | |
.panel-body | |
- @movie.comments.each do |comment| | |
%h5= comment.author_name | |
%p= comment.body | |
.panel-footer | |
= simple_form_for @comment do |f| | |
= f.input :body, input_html: {class: "form-control"} | |
= f.submit "Add Comment", class: "btn btn-default btn-sm" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment