Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perform crud operations #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/movies.js
Original file line number Diff line number Diff line change
@@ -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.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/movies.scss
Original file line number Diff line number Diff line change
@@ -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/
48 changes: 48 additions & 0 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/movies_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module MoviesHelper
end
16 changes: 15 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@
</head>
<body>

<div class="container">

<%= link_to "Anasayfa", root_path %> | <%= link_to "Hakkkında", about_path %> | <%= link_to "İletişim", contact_path %>

<br />

<%= yield %>
<%= yield %>
</div>

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>



</body>
</html>
33 changes: 33 additions & 0 deletions app/views/movies/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<div class="row">
<div class="col-md-6 col-md-offset-3">


<%= form_for @movie do |f|%>
<div class="form-group">
<%=f.label :title %>
<%=f.text_field :title , class: 'form-control'%>
</div>

<div class="form-group">
<%=f.label :director %>
<%=f.text_field :director, class: 'form-control'%>
</div>
<div class="form-group">
<%=f.label :country %>
<%=f.text_field :country, class: 'form-control'%>
</div>
<div class="form-group">
<%=f.label :date %>
<%=f.text_field :date, class: 'form-control'%>
</div>
<div class="form-group">
<%=f.label :description %>
<%=f.text_area :description, class: 'form-control' %>
</div>

<div class="form-group">
<%=f.submit 'Gönder', class: 'form-control btn btn-success'%>
</div>
<% end %>
</div>
</div>
10 changes: 10 additions & 0 deletions app/views/movies/_movie.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@


<tr>
<td> <%= link_to movie.title , movie_path(movie)%> </td>
<td> <%= movie.date %> </td>
<td> <%= movie.director%> </td>

<td> <%=link_to 'Edit' , edit_movie_path(movie) %> </td>
<td> <%= link_to 'Delete' , movie_path(movie), method: :delete , data: {confirm: 'Are you sure, you want to delete this movie' }%> </td>
</tr>
2 changes: 2 additions & 0 deletions app/views/movies/create.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Movies#create</h1>
<p>Find me in app/views/movies/create.html.erb</p>
4 changes: 4 additions & 0 deletions app/views/movies/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Movies#edit</h1>
<p>Find me in app/views/movies/edit.html.erb</p>

<%= render 'form'%>
11 changes: 11 additions & 0 deletions app/views/movies/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>All Movies</h1>
<h3> <%= link_to "Add new movie", new_movie_path%> </h3>
<table class="table table-striped">
<th>Title</th>
<th>Year</th>
<th>Director</th>
<th></th>
<th></th>

<%= render @movies %>
</table>
4 changes: 4 additions & 0 deletions app/views/movies/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Movies#new</h1>
<p>Find me in app/views/movies/new.html.erb</p>

<%= render 'form'%>
21 changes: 21 additions & 0 deletions app/views/movies/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>Movies#show</h1>
<p>Find me in app/views/movies/show.html.erb</p>

<table class="table table-striped">



<tr>
<td> <%[email protected]%> </td>
<td> <%[email protected]%> </td>
<td> <%[email protected]%> </td>
<td> <%[email protected]%> </td>
<td> <%[email protected]%> </td>


</tr>

</table>

<%= link_to 'Edit' , edit_movie_path(@movie)%>
<%= link_to 'Movies' , movies_path%>
2 changes: 2 additions & 0 deletions app/views/movies/update.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Movies#update</h1>
<p>Find me in app/views/movies/update.html.erb</p>
6 changes: 0 additions & 6 deletions app/views/pages/home.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
<h1>Anasayfa</h1>

<h4>Film Listesi</h4>
<ul>
<% @movies.each do |movie| %>
<li> <%= movie.title %> </li>
<% end %>
</ul>
9 changes: 6 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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