Created
November 27, 2012 15:19
-
-
Save siddartha/4154757 to your computer and use it in GitHub Desktop.
Categorie
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
<%= simple_form_for(@category) do |f| %> | |
<%= f.error_notification %> | |
<div class="form-inputs"> | |
<%= f.input :name %> | |
<%= f.input :description %> | |
<%= f.input :parent_id %> | |
</div> | |
<div class="form-actions"> | |
<%= f.button :submit %> | |
</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
class Categorie < ActiveRecord::Base | |
rolify | |
# Include default devise modules. Others available are: | |
# :token_authenticatable, :confirmable, | |
# :lockable, :timeoutable and :omniauthable | |
devise :database_authenticatable, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable | |
# Setup accessible (or protected) attributes for your model | |
attr_accessible :role_ids, :as => :admin | |
attr_accessible :description, :name, :parent_id | |
validates_presence_of :name | |
validates_uniqueness_of :name, :case_sensitive => false | |
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
class CategoriesController < ApplicationController | |
# GET /categories | |
# GET /categories.json | |
def index | |
@categories = Categorie.all | |
respond_to do |format| | |
format.html # index.html.erb | |
format.json { render json: @categories } | |
end | |
end | |
# GET /categories/1 | |
# GET /categories/1.json | |
def show | |
@category = Categorie.find(params[:id]) | |
respond_to do |format| | |
format.html # show.html.erb | |
format.json { render json: @category } | |
end | |
end | |
# GET /categories/new | |
# GET /categories/new.json | |
def new | |
@category = Categorie.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @category } | |
end | |
end | |
# GET /categories/1/edit | |
def edit | |
@category = Categorie.find(params[:id]) | |
end | |
# POST /categories | |
# POST /categories.json | |
def create | |
@category = Categorie.new(params[:category]) | |
respond_to do |format| | |
if @category.save | |
format.html { redirect_to @category, notice: 'Categorie was successfully created.' } | |
format.json { render json: @category, status: :created, location: @category } | |
else | |
format.html { render action: "new" } | |
format.json { render json: @category.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# PUT /categories/1 | |
# PUT /categories/1.json | |
def update | |
@category = Categorie.find(params[:id]) | |
respond_to do |format| | |
if @category.update_attributes(params[:category]) | |
format.html { redirect_to @category, notice: 'Categorie was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @category.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /categories/1 | |
# DELETE /categories/1.json | |
def destroy | |
@category = Categorie.find(params[:id]) | |
@category.destroy | |
respond_to do |format| | |
format.html { redirect_to categories_url } | |
format.json { head :no_content } | |
end | |
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
<h1>New category</h1> | |
<%= render 'form' %> | |
<%= link_to 'Back', categories_path %> |
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
Annuaire::Application.routes.draw do | |
authenticated :user do | |
root :to => 'home#index' | |
end | |
root :to => "home#index" | |
devise_for :users | |
resources :users, :categories | |
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
<p id="notice"><%= notice %></p> | |
<p> | |
<b>Name:</b> | |
<%= @category.name %> | |
</p> | |
<p> | |
<b>Description:</b> | |
<%= @category.description %> | |
</p> | |
<p> | |
<b>Parent:</b> | |
<%= @category.parent_id %> | |
</p> | |
<%= link_to 'Edit', edit_category_path(@category) %> | | |
<%= link_to 'Back', categories_path %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment