Skip to content

Commit

Permalink
Set eager_load on productons config
Browse files Browse the repository at this point in the history
Change models/controllers to use strong parameters
  • Loading branch information
mariochavez committed Jan 29, 2013
1 parent 796c5b3 commit 9d2325a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
19 changes: 14 additions & 5 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def new
end

def create
@product = Product.new params[:product]
@product = Product.new form_params

if @product.valid?
@product.save
Expand All @@ -21,22 +21,31 @@ def create
end

def show
@product = Product.find_by_id params[:id]
@product = Product.find_by_id model_id
end

def edit
@product = Product.find_by_id params[:id]
@product = Product.find_by_id model_id
@categories = Category.all
end

def update
@product = Product.find_by_id params[:id]
@product = Product.find_by_id model_id

if @product.update_attributes params[:product]
if @product.update_attributes form_params
return redirect_to products_path, notice: "Your product #{@product.name} has been updated!"
end

@categories = Category.all
render :edit
end

private
def form_params
params.require(:product).permit(:active, :description, :name, :price, :category_id)
end

def model_id
params.permit :id
end
end
2 changes: 0 additions & 2 deletions app/models/category.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Category < ActiveRecord::Base
has_many :products

attr_accessible :name

validates :name, presence: true
end
2 changes: 0 additions & 2 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ class Product < ActiveRecord::Base

belongs_to :category

attr_accessible :active, :description, :name, :price, :category_id

validates :name, :category_id, presence: true

def set_defaults
Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Code is not reloaded between requests
config.cache_classes = true

# Do not eager load code on boot.
config.eager_load = true

# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
Expand Down

0 comments on commit 9d2325a

Please sign in to comment.