Created
November 30, 2013 00:41
-
-
Save JRizzle88/7713901 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
# views/admin/product_categories/_form.html.erb | |
<%= simple_form_for(@product_category) do |f| %> | |
<%= f.error_notification %> | |
<div class="form-inputs"> | |
<%= f.input :name %> | |
</div> | |
<div class="form-actions"> | |
<%= f.button :submit, 'Add Category' %> | |
</div> | |
<% 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
*************** ERROR MESSAGE *************** | |
undefined method `model_name' for NilClass:Class | |
pointing to the simple_form_for(@product_category) and @product_category is what it is throwing the error for, it is set above in the controller index. | |
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
# /controllers/admin/product_categories_controller.rb | |
class Admin::ProductCategoriesController < ApplicationController | |
before_action :set_product_category, only: [:show, :edit, :update, :destroy] | |
layout 'dashboard' | |
before_filter :authenticate_user! | |
before_filter do | |
redirect_to new_user_session_path unless current_user && current_user.admin? | |
end | |
# GET /product_categories | |
# GET /product_categories.json | |
def index | |
@product_categories = ProductCategory.all.paginate page: params[:page], | |
per_page: 10 | |
end | |
# GET /product_categories/1 | |
# GET /product_categories/1.json | |
def show | |
end | |
# GET /product_categories/new | |
def new | |
@product_category = ProductCategory.new | |
end | |
# GET /product_categories/1/edit | |
def edit | |
end | |
# POST /product_categories | |
# POST /product_categories.json | |
def create | |
@product_category = ProductCategory.new(product_category_params) | |
respond_to do |format| | |
if @product_category.save | |
format.html { redirect_to admin_product_categories_path(@product_categories), | |
notice: 'Product Category successfully created.' } | |
format.json { render action: 'show', | |
status: :created, location: @product_category } | |
else | |
format.html { render action: 'new' } | |
format.json { render json: @product_category.errors, | |
status: :unprocessable_entity } | |
end | |
end | |
end | |
# PATCH/PUT /product_categories/1 | |
# PATCH/PUT /product_categories/1.json | |
def update | |
respond_to do |format| | |
if @product_category.update(product_category_params) | |
format.html { redirect_to admin_product_categories_path(@product_categories), | |
notice: 'Product Category successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @product_category.errors, | |
status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /product_categories/1 | |
# DELETE /product_categories/1.json | |
def destroy | |
@product_category.destroy | |
respond_to do |format| | |
format.html { redirect_to [:admin_product_categories, @product_categories] } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_product_category | |
@product_category = ProductCategory.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def product_category_params | |
params.require(:product_category).permit(:name) | |
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
# /models/product_category.rb | |
class ProductCategory < ActiveRecord::Base | |
belongs_to :products | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment