Skip to content

Commit

Permalink
Migration to rails4: completed rcast 415
Browse files Browse the repository at this point in the history
  • Loading branch information
multiscan committed Jul 1, 2013
1 parent d3b9699 commit 36c18e9
Show file tree
Hide file tree
Showing 30 changed files with 107 additions and 66 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'mysql2'
gem 'activerecord-mysql-adapter'

# --- backward compatibility (TO BE REMOVED!)
gem 'protected_attributes'
# gem 'protected_attributes'

# ---------------------------------------------------- CAPISTRANO FOR DEPLOYMENT
gem 'capistrano'
Expand All @@ -31,6 +31,9 @@ gem "rolify", ">= 3.2.0"
# --- app configuration: config/application.yml
gem "figaro", ">= 0.5.0"


gem 'rails3-jquery-autocomplete' #, '1.0.9'

# --------------------------------------------------------------------------- js
gem 'jquery-rails'
# --- for easily passing variables to javascript
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ GEM
bundler (>= 1.3.0, < 2.0)
railties (= 4.0.0)
sprockets-rails (~> 2.0.0)
rails3-jquery-autocomplete (0.6.0)
railties (4.0.0)
actionpack (= 4.0.0)
activesupport (= 4.0.0)
Expand Down Expand Up @@ -238,6 +239,7 @@ DEPENDENCIES
protected_attributes
quiet_assets (>= 1.0.1)
rails (= 4.0.0)
rails3-jquery-autocomplete
rolify (>= 3.2.0)
rvm-capistrano
sass-rails
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/adm/admins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Adm::AdminsController < AdmController
before_filter :administrator_only!
before_action :administrator_only!

# GET /adm/admins
# GET /adm/admins.json
Expand Down Expand Up @@ -42,7 +42,7 @@ def edit
# POST /adm/admins
# POST /adm/admins.json
def create
@admin = Admin.new(params[:admin])
@admin = Admin.new(admin_params)

respond_to do |format|
if @admin.save
Expand All @@ -61,7 +61,7 @@ def update
@admin = Admin.find(params[:id])

respond_to do |format|
if @admin.update_attributes(params[:admin])
if @admin.update_attributes(admin_params)
format.html { redirect_to [:adm, @admin], notice: 'Admin was successfully updated.' }
format.json { head :no_content }
else
Expand All @@ -82,4 +82,11 @@ def destroy
format.json { head :no_content }
end
end

private

def admin_params
params.require(:admin).permit :name, :email, :role, :password, :password_confirmation, :remember_me, :lab_ids
end

end
15 changes: 11 additions & 4 deletions app/controllers/adm/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def edit
# POST /adm/books
def create
if params[:isbn_step]
@books=Book.new_given_isbn(params[:book][:isbn])
@books=Book.new_given_isbn(book_params[:isbn])
if @books.count == 1
@book=@books.first
if @book.new_record?
Expand All @@ -52,7 +52,7 @@ def create
end
else
if @books.first.new_record?
@book = Book.new(params[:book])
@book = Book.new(book_params)
render "new_as_merge"
else
@isbn = params[:book][:isbn]
Expand All @@ -63,7 +63,7 @@ def create
end
end
else
@book = Book.new(params[:book])
@book = Book.new(book_params)

respond_to do |format|
if @book.save
Expand All @@ -80,7 +80,7 @@ def update
@book = Book.find(params[:id])

respond_to do |format|
if @book.update_attributes(params[:book])
if @book.update_attributes(book_params)
format.html { redirect_to @book, notice: 'Book was successfully updated.' }
else
format.html { render action: "edit" }
Expand All @@ -97,4 +97,11 @@ def destroy
format.html { redirect_to books_url }
end
end

private

def book_params
params.require(:book).permit :abstract, :author, :call1, :call2, :call3, :call4, :categories, :collation, :collection, :currency, :edition, :editor, :idx, :isbn, :language, :notes, :price, :pubyear, :title, :toc, :publisher, :publisher_name, :subtitle, :volume
end

end
9 changes: 8 additions & 1 deletion app/controllers/adm/deg_isbns_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def edit
def update
@degisbn=DegIsbn.find(params["id"])
isbn=@degisbn.isbn
@book=Book.new(params["book"].merge({:isbn=>isbn}))
@book=Book.new(book_params.merge({:isbn=>isbn}))
if @book.save
@degisbn.count = @degisbn.count + 1
@degisbn.books.find(params["merge_book_ids"]).each do |b|
Expand All @@ -45,4 +45,11 @@ def update
render :action => "edit"
end
end

private

def book_params
params.require(:book).permit :abstract, :author, :call1, :call2, :call3, :call4, :categories, :collation, :collection, :currency, :edition, :editor, :idx, :isbn, :language, :notes, :price, :pubyear, :title, :toc, :publisher, :publisher_name, :subtitle, :volume
end

end
2 changes: 1 addition & 1 deletion app/controllers/adm/items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Adm::ItemsController < AdmController
before_filter :set_book, :only => [:new, :create]
before_action :set_book, :only => [:new, :create]
load_and_authorize_resource :except => [:index]

# GET /items
Expand Down
13 changes: 10 additions & 3 deletions app/controllers/adm/labs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Adm::LabsController < AdmController
before_filter :administrator_only!
before_action :administrator_only!

# GET /adm/labs
# GET /adm/labs.json
Expand Down Expand Up @@ -44,7 +44,7 @@ def edit
# POST /adm/labs
# POST /adm/labs.json
def create
@lab = Lab.new(params[:adm_lab])
@lab = Lab.new(lab_params)

respond_to do |format|
if @lab.save
Expand All @@ -63,7 +63,7 @@ def update
@lab = Lab.find(params[:id])

respond_to do |format|
if @lab.update_attributes(params[:adm_lab])
if @lab.update_attributes(lab_params)
format.html { redirect_to @lab, notice: 'Lab was successfully updated.' }
format.json { head :no_content }
else
Expand All @@ -84,4 +84,11 @@ def destroy
format.json { head :no_content }
end
end

private

def lab_params
params.require(:adm_lab).permit :name, :nick
end

end
11 changes: 9 additions & 2 deletions app/controllers/adm/locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def edit
# POST /adm/locations
# POST /adm/locations.json
def create
@location = Location.new(params[:location])
@location = Location.new(location_params)

respond_to do |format|
if @location.save
Expand All @@ -66,7 +66,7 @@ def update
@location = Location.find(params[:id])

respond_to do |format|
if @location.update_attributes(params[:location])
if @location.update_attributes(location_params)
format.html { redirect_to adm_locations_url, notice: "Location #{@location.name} was successfully updated." }
format.json { head :no_content }
else
Expand All @@ -87,4 +87,11 @@ def destroy
format.json { head :no_content }
end
end

private

def location_params
params.require(:location).permit(:name)
end

end
8 changes: 7 additions & 1 deletion app/controllers/adm/publisher_mergers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def new
# POST /publisher_mergers
def create
@publishers=Publisher.find(params["mergenda_ids"])
@publisher=Publisher.new(params["publisher"])
@publisher=Publisher.new(publisher_params)
if params["commit"] == "Merge"
render action: "edit"
else
Expand All @@ -35,4 +35,10 @@ def create
end
end

private

def publisher_params
params.require(:publisher).permit(:name)
end

end
13 changes: 10 additions & 3 deletions app/controllers/adm/publishers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Adm::PublishersController < AdmController
before_filter :administrator_only!
before_action :administrator_only!

# GET /adm/publishers
# GET /adm/publishers.json
Expand Down Expand Up @@ -42,7 +42,7 @@ def edit
# POST /adm/publishers
# POST /adm/publishers.json
def create
@publisher = Publisher.new(params[:publisher])
@publisher = Publisher.new(publisher_params)

respond_to do |format|
if @publisher.save
Expand All @@ -61,7 +61,7 @@ def update
@publisher = Publisher.find(params[:id])

respond_to do |format|
if @publisher.update_attributes(params[:publisher])
if @publisher.update_attributes(publisher_params)
format.html { redirect_to @publisher, notice: 'Publisher was successfully updated.' }
format.json { head :no_content }
else
Expand All @@ -82,4 +82,11 @@ def destroy
format.json { head :no_content }
end
end

private

def publisher_params
params.require(:publisher).permit(:name)
end

end
10 changes: 8 additions & 2 deletions app/controllers/adm/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def edit
# POST /admin/users
# POST /admin/users.json
def create
@user = User.new(params[:user])
@user = User.new(user_params)

respond_to do |format|
if @user.save
Expand All @@ -74,7 +74,7 @@ def update
@user = User.find(params[:id])

respond_to do |format|
if @user.update_attributes(params[:user])
if @user.update_attributes(user_params)
format.html { redirect_to [:adm, @user], notice: 'User was successfully updated.' }
format.json { head :no_content }
else
Expand All @@ -101,4 +101,10 @@ def destroy
end
end

private

def user_params
params.require(:user).permit(:name, :email, :nebis, :legacy_id, :lab_id, :notes)
end

end
2 changes: 1 addition & 1 deletion app/controllers/adm_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AdmController < ApplicationController
before_filter :authenticate_admin!
before_action :authenticate_admin!

def administrator_only!
# raise User::NotAuthorized unless current_user.admin?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :set_gon_for_admin
before_action :set_gon_for_admin

# check_authorization

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/nebis_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class NebisController < ApplicationController

before_filter :nebis_session, :only => :show
before_action :nebis_session, :only => :show

def show
@user = User.find_by_nebis(params[:id])
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UsersController < ApplicationController

before_filter :authenticate_admin!, :only => [:show]
before_action :authenticate_admin!, :only => [:show]

# GET /users/1
# GET /users/1.json
Expand Down
6 changes: 3 additions & 3 deletions app/models/admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class Admin < ActiveRecord::Base
# :recoverable, :rememberable, :trackable, :validatable
devise :database_authenticatable, :recoverable

# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :role, :password, :password_confirmation, :remember_me, :lab_ids
# attr_accessible :title, :body
# # Setup accessible (or protected) attributes for your model
# attr_accessible :name, :email, :role, :password, :password_confirmation, :remember_me, :lab_ids
# # attr_accessible :title, :body

has_and_belongs_to_many :labs, :class_name => "Lab", :join_table => "operatorships"
has_many :inventory_sessions, :class_name => "InventorySession", :foreign_key => "admin_id", :order => 'updated_at DESC'
Expand Down
2 changes: 0 additions & 2 deletions app/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
class Book < ActiveRecord::Base
extend Memoist

attr_accessible :abstract, :author, :call1, :call2, :call3, :call4, :categories, :collation, :collection, :currency, :edition, :editor, :idx, :isbn, :language, :notes, :price, :pubyear, :title, :toc, :publisher, :publisher_name, :subtitle, :volume

has_many :items, :as => :inventoriable
# has_many :loans, :class_name => "Loan", :foreign_key => "book_id"
# has_many :checkouts, :class_name => "Loan", :foreign_key => "book_id", :conditions=>{:return_date=>nil}
Expand Down
2 changes: 1 addition & 1 deletion app/models/deg_isbn.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class DegIsbn < ActiveRecord::Base
attr_accessible :isbn, :count, :mergeables

has_many :books, :class_name => "Book", :foreign_key => "isbn", :primary_key => "isbn"

# def mergeables
Expand Down
4 changes: 3 additions & 1 deletion app/models/good.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Good < ActiveRecord::Base
attr_accessible :inventory_session_id, :item_id, :previous_shelf_id, :current_shelf_id

# attr_accessible :inventory_session_id, :item_id, :previous_shelf_id, :current_shelf_id

belongs_to :item, :class_name => "Item", :foreign_key => "item_id"
belongs_to :inventory_session, :class_name => "InventorySession", :foreign_key => "inventory_session_id"
belongs_to :current_shelf, :class_name => "Shelf", :foreign_key => "current_shelf_id"
Expand Down
1 change: 0 additions & 1 deletion app/models/lab.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Lab < ActiveRecord::Base
attr_accessible :name, :nick
has_many :users
has_many :items
has_many :book_items, :class_name => "Item", :conditions=>{:inventoriable_type=>"Book"}, :include => :inventoriable
Expand Down
2 changes: 1 addition & 1 deletion app/models/loan.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Loan < ActiveRecord::Base
attr_accessible :item, :user
# attr_accessible :item, :user

belongs_to :user, :class_name => "User", :foreign_key => "user_id"
belongs_to :item, :class_name => "Item", :foreign_key => "item_id", :include => :inventoriable
Expand Down
1 change: 0 additions & 1 deletion app/models/location.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Location < ActiveRecord::Base
attr_accessible :name
validates_uniqueness_of :name, :on => :create, :message => "a room with this name already exists"

def self.names_list
Expand Down
1 change: 0 additions & 1 deletion app/models/publisher.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Publisher < ActiveRecord::Base
attr_accessible :name

has_many :books

Expand Down
Loading

0 comments on commit 36c18e9

Please sign in to comment.