From bce2e8daf1952289fc2b37ab7d7c04e2d6aa9781 Mon Sep 17 00:00:00 2001 From: hakan280 Date: Sun, 20 Mar 2016 14:02:49 +0200 Subject: [PATCH] perfom crud operations --- app/assets/javascripts/movies.js | 2 ++ app/assets/stylesheets/movies.scss | 3 ++ app/controllers/movies_controller.rb | 48 ++++++++++++++++++++++++++ app/helpers/movies_helper.rb | 2 ++ app/views/layouts/application.html.erb | 16 ++++++++- app/views/movies/_form.html.erb | 33 ++++++++++++++++++ app/views/movies/_movie.html.erb | 10 ++++++ app/views/movies/create.html.erb | 2 ++ app/views/movies/edit.html.erb | 4 +++ app/views/movies/index.html.erb | 11 ++++++ app/views/movies/new.html.erb | 4 +++ app/views/movies/show.html.erb | 21 +++++++++++ app/views/movies/update.html.erb | 2 ++ app/views/pages/home.html.erb | 6 ---- config/routes.rb | 9 +++-- 15 files changed, 163 insertions(+), 10 deletions(-) create mode 100644 app/assets/javascripts/movies.js create mode 100644 app/assets/stylesheets/movies.scss create mode 100644 app/controllers/movies_controller.rb create mode 100644 app/helpers/movies_helper.rb create mode 100644 app/views/movies/_form.html.erb create mode 100644 app/views/movies/_movie.html.erb create mode 100644 app/views/movies/create.html.erb create mode 100644 app/views/movies/edit.html.erb create mode 100644 app/views/movies/index.html.erb create mode 100644 app/views/movies/new.html.erb create mode 100644 app/views/movies/show.html.erb create mode 100644 app/views/movies/update.html.erb diff --git a/app/assets/javascripts/movies.js b/app/assets/javascripts/movies.js new file mode 100644 index 0000000..dee720f --- /dev/null +++ b/app/assets/javascripts/movies.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/movies.scss b/app/assets/stylesheets/movies.scss new file mode 100644 index 0000000..b86dfed --- /dev/null +++ b/app/assets/stylesheets/movies.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the Movies controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb new file mode 100644 index 0000000..bc2192b --- /dev/null +++ b/app/controllers/movies_controller.rb @@ -0,0 +1,48 @@ +class MoviesController < ApplicationController + def index + @movies = Movie.all + end + + def show + @movie = Movie.find(params[:id]) + end + + def new + @movie = Movie.new + end + + def create + @movie = Movie.new(movie_params) + if @movie.save + redirect_to @movie + else + render 'new' + end + + end + + def edit + @movie = Movie.find(params[:id]) + end + + def update + @movie = Movie.find(params[:id]) + if @movie.update(movie_params) + redirect_to(@movie) + else + render "edit" + end + end + + def destroy + @movie =Movie.find(params[:id]) + @movie.destroy + redirect_to movies_path + end + + private + def movie_params + params.require(:movie).permit(:title,:date ,:director , :description , :country) + + end +end diff --git a/app/helpers/movies_helper.rb b/app/helpers/movies_helper.rb new file mode 100644 index 0000000..493eee5 --- /dev/null +++ b/app/helpers/movies_helper.rb @@ -0,0 +1,2 @@ +module MoviesHelper +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 72827c6..f1c69ac 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,11 +8,25 @@ +
+ <%= link_to "Anasayfa", root_path %> | <%= link_to "Hakkkında", about_path %> | <%= link_to "İletişim", contact_path %>
-<%= yield %> + <%= yield %> +
+ + + + + + + + + + + diff --git a/app/views/movies/_form.html.erb b/app/views/movies/_form.html.erb new file mode 100644 index 0000000..1649f9c --- /dev/null +++ b/app/views/movies/_form.html.erb @@ -0,0 +1,33 @@ +
+
+ + + <%= form_for @movie do |f|%> +
+ <%=f.label :title %> + <%=f.text_field :title , class: 'form-control'%> +
+ +
+ <%=f.label :director %> + <%=f.text_field :director, class: 'form-control'%> +
+
+ <%=f.label :country %> + <%=f.text_field :country, class: 'form-control'%> +
+
+ <%=f.label :date %> + <%=f.text_field :date, class: 'form-control'%> +
+
+ <%=f.label :description %> + <%=f.text_area :description, class: 'form-control' %> +
+ +
+ <%=f.submit 'Gönder', class: 'form-control btn btn-success'%> +
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/movies/_movie.html.erb b/app/views/movies/_movie.html.erb new file mode 100644 index 0000000..cfbabb3 --- /dev/null +++ b/app/views/movies/_movie.html.erb @@ -0,0 +1,10 @@ + + + + <%= link_to movie.title , movie_path(movie)%> + <%= movie.date %> + <%= movie.director%> + + <%=link_to 'Edit' , edit_movie_path(movie) %> + <%= link_to 'Delete' , movie_path(movie), method: :delete , data: {confirm: 'Are you sure, you want to delete this movie' }%> + diff --git a/app/views/movies/create.html.erb b/app/views/movies/create.html.erb new file mode 100644 index 0000000..af70ce5 --- /dev/null +++ b/app/views/movies/create.html.erb @@ -0,0 +1,2 @@ +

Movies#create

+

Find me in app/views/movies/create.html.erb

diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000..0f3e1a7 --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,4 @@ +

Movies#edit

+

Find me in app/views/movies/edit.html.erb

+ +<%= render 'form'%> \ No newline at end of file diff --git a/app/views/movies/index.html.erb b/app/views/movies/index.html.erb new file mode 100644 index 0000000..f3120d3 --- /dev/null +++ b/app/views/movies/index.html.erb @@ -0,0 +1,11 @@ +

All Movies

+

<%= link_to "Add new movie", new_movie_path%>

+ + + + + + + + <%= render @movies %> +
TitleYearDirector
\ No newline at end of file diff --git a/app/views/movies/new.html.erb b/app/views/movies/new.html.erb new file mode 100644 index 0000000..a4b6489 --- /dev/null +++ b/app/views/movies/new.html.erb @@ -0,0 +1,4 @@ +

Movies#new

+

Find me in app/views/movies/new.html.erb

+ +<%= render 'form'%> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb new file mode 100644 index 0000000..cea7acb --- /dev/null +++ b/app/views/movies/show.html.erb @@ -0,0 +1,21 @@ +

Movies#show

+

Find me in app/views/movies/show.html.erb

+ + + + + + + + + + + + + + + +
<%=@movie.title%> <%=@movie.country%> <%=@movie.date%> <%=@movie.director%> <%=@movie.description%>
+ +<%= link_to 'Edit' , edit_movie_path(@movie)%> +<%= link_to 'Movies' , movies_path%> diff --git a/app/views/movies/update.html.erb b/app/views/movies/update.html.erb new file mode 100644 index 0000000..1d77c2e --- /dev/null +++ b/app/views/movies/update.html.erb @@ -0,0 +1,2 @@ +

Movies#update

+

Find me in app/views/movies/update.html.erb

diff --git a/app/views/pages/home.html.erb b/app/views/pages/home.html.erb index 56ff891..c5e6e0c 100644 --- a/app/views/pages/home.html.erb +++ b/app/views/pages/home.html.erb @@ -1,8 +1,2 @@

Anasayfa

-

Film Listesi

- diff --git a/config/routes.rb b/config/routes.rb index 491f704..973dbfe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,9 @@ Rails.application.routes.draw do - root to: "pages#home" - get 'hakkinda', to: "about", as: :about - get 'iletisim', to: "contact", as: :contact + + + root to: "movies#index" + resources :movies + get 'hakkinda', to: "pages#about", as: :about + get 'iletisim', to: "pages#contact", as: :contact end