Created
November 19, 2011 23:57
-
-
Save jagmitg/1379562 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
require 'nokogiri' | |
require 'open-uri' | |
class CinemaFilms | |
belongs_to :cinemas | |
def self.get_film_links | |
doc = Nokogiri::XML(open('http://jagmit.co.uk/ruby/all-performances.xml')) | |
doc.xpath('//film[@title]').map do |i| | |
{title: i[:title], rating: i[:rating], release: i[:release], length: i[:length], poster: i[:poster], director: i[:director], synopsis: i[:synopsis], cast: i[:cast] } | |
end | |
end | |
def self.store(arr) | |
arr.each do |i| | |
# cinema = Cinema.new(:name => i[:name], :url => i[:url]) | |
film = Film.new(i) | |
film.save | |
end | |
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
require 'nokogiri' | |
require 'open-uri' | |
class CinemaSite | |
has_many :films | |
def self.get_cinema_links | |
doc = Nokogiri::XML(open('http://jagmit.co.uk/ruby/all-performances.xml')) | |
doc.xpath('//cinema[@name]').map do |i| | |
{cinema_id: i[:id], name: i[:name], url: i[:address], postcode: i[:postcode], telephone: i[:phone]} | |
end | |
end | |
def self.store(arr) | |
arr.each do |i| | |
# cinema = Cinema.new(:name => i[:name], :url => i[:url]) | |
cinema = Cinema.new(i) | |
cinema.save | |
end | |
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 CinemasController < ApplicationController | |
# GET /cinemas | |
# GET /cinemas.json | |
def index | |
@cinemas = Cinema.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @cinemas } | |
end | |
end | |
# GET /cinemas/1 | |
# GET /cinemas/1.json | |
def show | |
@cinema = Cinema.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @cinema } | |
end | |
end | |
# GET /cinemas/new | |
# GET /cinemas/new.json | |
def new | |
@cinema = Cinema.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @cinema } | |
end | |
end | |
# GET /cinemas/1/edit | |
def edit | |
@cinema = Cinema.find(params[:id]) | |
end | |
# POST /cinemas | |
# POST /cinemas.json | |
def create | |
@cinema = Cinema.new(params[:cinema]) | |
respond_to do |format| | |
if @cinema.save | |
format.html { redirect_to @cinema, notice: 'Cinema was successfully created.' } | |
format.json { render json: @cinema, status: :created, location: @cinema } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @cinema.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /cinemas/1 | |
# PUT /cinemas/1.json | |
def update | |
@cinema = Cinema.find(params[:id]) | |
respond_to do |format| | |
if @cinema.update_attributes(params[:cinema]) | |
format.html { redirect_to @cinema, notice: 'Cinema was successfully updated.' } | |
format.json { head :ok } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @cinema.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /cinemas/1 | |
# DELETE /cinemas/1.json | |
def destroy | |
@cinema = Cinema.find(params[:id]) | |
@cinema.destroy | |
respond_to do |format| | |
format.html { redirect_to cinemas_url } | |
format.json { head :ok } | |
end | |
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 FilmsController < ApplicationController | |
# GET /films | |
# GET /films.json | |
def index | |
@films = Cinemas.find(params[:cinema_id]) | |
@cinema = @films.cinema | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @films } | |
end | |
end | |
# GET /films/1 | |
# GET /films/1.json | |
def show | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @film } | |
end | |
end | |
# GET /films/new | |
# GET /films/new.json | |
def new | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @film } | |
end | |
end | |
# GET /films/1/edit | |
def edit | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.find(params[:id]) | |
end | |
# POST /films | |
# POST /films.json | |
def create | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.new(params[:id]) | |
respond_to do |format| | |
if @film.save | |
format.html { redirect_to @film, notice: 'Film was successfully created.' } | |
format.json { render json: @film, status: :created, location: @film } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @film.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /films/1 | |
# PUT /films/1.json | |
def update | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.find(params[:id]) | |
respond_to do |format| | |
if @film.update_attributes(params[:film]) | |
format.html { redirect_to @film, notice: 'Film was successfully updated.' } | |
format.json { head :ok } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @film.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /films/1 | |
# DELETE /films/1.json | |
def destroy | |
@cinemas = Cinema.find(params[:cinema_id]) | |
@film = Film.find(params[:id]) | |
@film.destroy | |
respond_to do |format| | |
format.html { redirect_to films_url } | |
format.json { head :ok } | |
end | |
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
Morevue::Application.routes.draw do | |
# The priority is based upon order of creation: | |
# first created -> highest priority. | |
# Sample of regular route: | |
# match 'products/:id' => 'catalog#view' | |
# Keep in mind you can assign values other than :controller and :action | |
# Sample of named route: | |
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase | |
# This route can be invoked with purchase_url(:id => product.id) | |
# Sample resource route (maps HTTP verbs to controller actions automatically): | |
# resources :products | |
# Sample resource route with options: | |
# resources :products do | |
# member do | |
# get 'short' | |
# post 'toggle' | |
# end | |
# | |
# collection do | |
# get 'sold' | |
# end | |
# end | |
# Sample resource route with sub-resources: | |
# resources :products do | |
# resources :comments, :sales | |
# resource :seller | |
# end | |
# Sample resource route with more complex sub-resources | |
# resources :products do | |
# resources :comments | |
# resources :sales do | |
# get 'recent', :on => :collection | |
# end | |
# end | |
# Sample resource route within a namespace: | |
# namespace :admin do | |
# # Directs /admin/products/* to Admin::ProductsController | |
# # (app/controllers/admin/products_controller.rb) | |
# resources :products | |
# end | |
# You can have the root of your site routed with "root" | |
# just remember to delete public/index.html. | |
# root :to => 'welcome#index' | |
# See how all your routes lay out with "rake routes" | |
# This is a legacy wild controller route that's not recommended for RESTful applications. | |
# Note: This route will make all actions in every controller accessible via GET requests. | |
# match ':controller(/:action(/:id(.:format)))' | |
resources :apps | |
resources :cinemas | |
resources :films | |
resources :cinemas do | |
resources :films | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment