Created
November 27, 2012 15:44
-
-
Save siddartha/4154932 to your computer and use it in GitHub Desktop.
Category
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 %> | |
</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 CategoriesController < ApplicationController | |
# GET /categories | |
# GET /categories.json | |
def index | |
@categories = Category.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 = Category.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 = Category.new | |
respond_to do |format| | |
format.html # new.html.erb | |
format.json { render json: @category } | |
end | |
end | |
# GET /categories/1/edit | |
def edit | |
@category = Category.find(params[:id]) | |
end | |
# POST /categories | |
# POST /categories.json | |
def create | |
@category = Category.new(params[:category]) | |
respond_to do |format| | |
if @category.save | |
format.html { redirect_to @category, notice: 'Category 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 = Category.find(params[:id]) | |
respond_to do |format| | |
if @category.update_attributes(params[:category]) | |
format.html { redirect_to @category, notice: 'Category 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 = Category.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
class Category < ActiveRecord::Base | |
attr_accessible :description, :name, :parent | |
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
NoMethodError in Categories#index | |
Showing /home/mon_beau_path_vers_mon_app/web/annuaire/app/views/categories/index.html.erb where line #17 raised: | |
undefined method `parent' for #<Category:0x0000000454e6e8> | |
Extracted source (around line #17): | |
14: <tr> | |
15: <td><%= category.name %></td> | |
16: <td><%= category.description %></td> | |
17: <td><%= category.parent %></td> | |
18: <td><%= link_to 'Show', category %></td> | |
19: <td><%= link_to 'Edit', edit_category_path(category) %></td> | |
20: <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
app/views/categories/index.html.erb:17:in `block in _app_views_categories_index_html_erb___690230365758431318_33118580' | |
app/views/categories/index.html.erb:13:in `each' | |
app/views/categories/index.html.erb:13:in `_app_views_categories_index_html_erb___690230365758431318_33118580' | |
app/controllers/categories_controller.rb:7:in `index' | |
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>Listing categories</h1> | |
<table> | |
<tr> | |
<th>Name</th> | |
<th>Description</th> | |
<th>Parent</th> | |
<th></th> | |
<th></th> | |
<th></th> | |
</tr> | |
<% @categories.each do |category| %> | |
<tr> | |
<td><%= category.name %></td> | |
<td><%= category.description %></td> | |
<td><%= category.parent %></td> | |
<td><%= link_to 'Show', category %></td> | |
<td><%= link_to 'Edit', edit_category_path(category) %></td> | |
<td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
</tr> | |
<% end %> | |
</table> | |
<br /> | |
<%= link_to 'New Category', new_category_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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment