Last active
January 3, 2016 15:09
-
-
Save Veske/8481183 to your computer and use it in GitHub Desktop.
Movie updating
This file contains hidden or 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
| <% provide(:title, "Edit movie") %> | |
| <p class="content"> | |
| <p class="text"> | |
| Edit your account information here: | |
| </p> | |
| <%= form_for :movie do |f| %> | |
| <div class="forms"> | |
| <%= f.text_field :name, placeholder: "Name of the movie..." %> | |
| <%= f.text_area :description, placeholder: "Describe the movie..." %> | |
| <%= f.text_field :year, placeholder: "When was it released..." %> | |
| <%= f.submit 'Submit!' %></br> | |
| <%= link_to "Back to movies", movies_path, class: "black" %> | |
| </div> | |
| <% end %> |
This file contains hidden or 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
| Routing Error | |
| No route matches [POST] "/movies/1/edit" | |
| posts_path POST /posts(.:format) posts#create | |
| new_post_path GET /posts/new(.:format) posts#new | |
| post_path DELETE /posts/:id(.:format) posts#destroy | |
| users_path GET /users(.:format) users#index | |
| POST /users(.:format) users#create | |
| new_user_path GET /users/new(.:format) users#new | |
| edit_user_path GET /users/:id/edit(.:format) users#edit | |
| user_path GET /users/:id(.:format) users#show | |
| PATCH /users/:id(.:format) users#update | |
| PUT /users/:id(.:format) users#update | |
| DELETE /users/:id(.:format) users#destroy | |
| sessions_path POST /sessions(.:format) sessions#create | |
| new_session_path GET /sessions/new(.:format) sessions#new | |
| session_path DELETE /sessions/:id(.:format) sessions#destroy | |
| movies_path GET /movies(.:format) movies#index | |
| POST /movies(.:format) movies#create | |
| new_movie_path GET /movies/new(.:format) movies#new | |
| edit_movie_path GET /movies/:id/edit(.:format) movies#edit | |
| movie_path GET /movies/:id(.:format) movies#show | |
| PATCH /movies/:id(.:format) movies#update | |
| PUT /movies/:id(.:format) movies#update | |
| DELETE /movies/:id(.:format) movies#destroy | |
| shows_path GET /shows(.:format) shows#index | |
| POST /shows(.:format) shows#create | |
| new_show_path GET /shows/new(.:format) shows#new | |
| edit_show_path GET /shows/:id/edit(.:format) shows#edit | |
| show_path GET /shows/:id(.:format) shows#show | |
| PATCH /shows/:id(.:format) shows#update | |
| PUT /shows/:id(.:format) shows#update | |
| DELETE /shows/:id(.:format) shows#destroy | |
| posts_new_path GET /posts/new(.:format) posts#new | |
| form_home_path GET /form/home(.:format) form#home | |
| POST /form/home(.:format) form#home | |
| form_converter_path GET /form/converter(.:format) form#converter | |
| POST /form/converter(.:format) form#converter | |
| form_about_path GET /form/about(.:format) form#about | |
| root_path GET / form#home | |
| signout_path DELETE /signout(.:format) sessions#destroy |
This file contains hidden or 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 | |
| before_action :signed_in_user, only: [:index,:edit,:update, :destroy] | |
| before_action :admin_user, only: :destroy | |
| before_action :set_movie, only: [:show, :edit, :update, :destroy] | |
| def index | |
| @movies = Movie.all | |
| end | |
| def show | |
| @movie = Movie.find(params[:id]) | |
| end | |
| def new | |
| @movie = Movie.new | |
| end | |
| def create | |
| @movie = Movie.create(movie_params) | |
| if @movie.save | |
| flash[:success] = "Movie posted!" | |
| redirect_to movies_path | |
| else | |
| render new_movie_path | |
| end | |
| end | |
| def update | |
| if @movie.update_attributes(movie_params) | |
| flash[:success] = "Update successful" | |
| redirect_to @movie | |
| else | |
| render 'edit' | |
| end | |
| end | |
| def edit | |
| end | |
| def destroy | |
| Movie.find(params[:id]).destroy | |
| flash[:success] = "Movie deleted from the database." | |
| redirect_to movies_path | |
| end | |
| # Private section, makes the page unable to be seen for non logged in users | |
| private | |
| def movie_params | |
| params.require(:movie).permit(:name, :description, :year) | |
| end | |
| def user_params | |
| params.require(:user).permit(:name, :email, :password, :password_confirmation) | |
| end | |
| def admin_user | |
| redirect_to(root_url) unless current_user.admin? | |
| end | |
| # Redirecting not logged in user etc. | |
| def signed_in_user | |
| unless signed_in? | |
| store_location | |
| redirect_to '/sessions/new', notice: "Please sign in!" | |
| end | |
| end | |
| def set_movie | |
| @movie = Movie.find(params[:id]) | |
| end | |
| end |
This file contains hidden or 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
| Harjutus::Application.routes.draw do | |
| resources :posts, only: [:new, :create, :destroy] | |
| resources :users | |
| resources :sessions, only: [:new, :create, :destroy] | |
| resources :movies | |
| resources :shows | |
| get "posts/new" | |
| get "form/home" | |
| post "form/home" | |
| get "form/converter" | |
| post "form/converter" | |
| get "form/about" | |
| root 'form#home' | |
| require 'net/http' | |
| match "/signout", to: 'sessions#destroy', via: :delete | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment