├── install.rb ├── uninstall.rb ├── init.rb ├── test ├── test_helper.rb └── rails_simple_crud_actions_test.rb ├── tasks └── rails_simple_crud_actions_tasks.rake ├── README ├── Rakefile ├── MIT-LICENSE └── lib └── rails_simple_crud_actions.rb /install.rb: -------------------------------------------------------------------------------- 1 | # Install hook code here 2 | -------------------------------------------------------------------------------- /uninstall.rb: -------------------------------------------------------------------------------- 1 | # Uninstall hook code here 2 | -------------------------------------------------------------------------------- /init.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), "lib", "rails_simple_crud_actions") 2 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'active_support' 3 | require 'active_support/test_case' -------------------------------------------------------------------------------- /tasks/rails_simple_crud_actions_tasks.rake: -------------------------------------------------------------------------------- 1 | # desc "Explaining what the task does" 2 | # task :rails_simple_crud_actions do 3 | # # Task goes here 4 | # end 5 | -------------------------------------------------------------------------------- /test/rails_simple_crud_actions_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class RailsSimpleCrudActionsTest < ActiveSupport::TestCase 4 | # Replace this with your real tests. 5 | test "the truth" do 6 | assert true 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | RailsSimpleCrudActions 2 | ====================== 3 | 4 | This plugin is an action pack for "actions" framework (see http://github.com/html/actions) 5 | It contains standard CRUD (index, new, edit, show, create, destroy, update) from standard rails scaffolding. 6 | 7 | 8 | Example 9 | ======= 10 | 11 | class ArticlesController < ApplicationController 12 | action :index, :new, :edit, :show, :create, :destroy, :update 13 | end 14 | 15 | This is equal to have standard scaffolded controller ArticlesController. 16 | 17 | Copyright (c) 2009 [name of plugin creator], released under the MIT license 18 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | require 'rake/testtask' 3 | require 'rake/rdoctask' 4 | 5 | desc 'Default: run unit tests.' 6 | task :default => :test 7 | 8 | desc 'Test the rails_simple_crud_actions plugin.' 9 | Rake::TestTask.new(:test) do |t| 10 | t.libs << 'lib' 11 | t.libs << 'test' 12 | t.pattern = 'test/**/*_test.rb' 13 | t.verbose = true 14 | end 15 | 16 | desc 'Generate documentation for the rails_simple_crud_actions plugin.' 17 | Rake::RDocTask.new(:rdoc) do |rdoc| 18 | rdoc.rdoc_dir = 'rdoc' 19 | rdoc.title = 'RailsSimpleCrudActions' 20 | rdoc.options << '--line-numbers' << '--inline-source' 21 | rdoc.rdoc_files.include('README') 22 | rdoc.rdoc_files.include('lib/**/*.rb') 23 | end 24 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 [name of plugin creator] 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /lib/rails_simple_crud_actions.rb: -------------------------------------------------------------------------------- 1 | module Actions 2 | module Repository 3 | define_action :index do 4 | str = self.class.to_s.sub /Controller$/, '' 5 | var = "@#{str.underscore.pluralize}" 6 | model = str.singularize.camelize.constantize 7 | 8 | instance_variable_set var, model.all 9 | 10 | respond_to do |format| 11 | format.html 12 | format.xml { render :xml => instance_variable_get(var) } 13 | end 14 | end 15 | 16 | define_action :new do 17 | str = self.class.to_s.sub /Controller$/, '' 18 | var = "@#{str.underscore.singularize}" 19 | model = str.singularize.camelize.constantize 20 | 21 | instance_variable_set var, model.new 22 | 23 | respond_to do |format| 24 | format.html 25 | format.xml { render :xml => instance_variable_get(var) } 26 | end 27 | end 28 | 29 | define_action :edit do 30 | str = self.class.to_s.sub /Controller$/, '' 31 | var = "@#{str.underscore.singularize}" 32 | model = str.singularize.camelize.constantize 33 | 34 | instance_variable_set var, model.find(params[:id]) 35 | end 36 | 37 | define_action :show do 38 | str = self.class.to_s.sub /Controller$/, '' 39 | var = "@#{str.underscore.singularize}" 40 | model = str.singularize.camelize.constantize 41 | 42 | instance_variable_set var, model.find(params[:id]) 43 | respond_to do |format| 44 | format.html 45 | format.xml { render :xml => instance_variable_get(var) } 46 | end 47 | end 48 | 49 | define_action :create do 50 | str = self.class.to_s.sub /Controller$/, '' 51 | var = "@#{str.underscore.singularize}" 52 | model = str.singularize.camelize.constantize 53 | 54 | item = model.new(params[str.underscore.singularize]) 55 | instance_variable_set(var, item) 56 | 57 | respond_to do |format| 58 | if item.save 59 | flash[:notice] = str.singularize.camelize + ' was successfully created.' 60 | format.html { redirect_to(item) } 61 | format.xml { render :xml => item, :status => :created, :location => item } 62 | else 63 | format.html { render :action => "new" } 64 | format.xml { render :xml => item.errors, :status => :unprocessable_entity } 65 | end 66 | end 67 | end 68 | 69 | define_action :destroy do 70 | str = self.class.to_s.sub /Controller$/, '' 71 | var = "@#{str.underscore.singularize}" 72 | model = str.singularize.camelize.constantize 73 | 74 | item = model.find(params[:id]) 75 | flash[:notice] = str.singularize + ' was successfully destroyed' 76 | item.destroy 77 | 78 | respond_to do |format| 79 | format.html { redirect_to(eval("#{str.underscore.pluralize}_url")) } 80 | format.xml { head :ok } 81 | end 82 | end 83 | 84 | define_action :update do 85 | str = self.class.to_s.sub /Controller$/, '' 86 | var = "@#{str.underscore.singularize}" 87 | model = str.singularize.camelize.constantize 88 | 89 | instance_variable_set var, (item = model.find(params[:id])) 90 | 91 | respond_to do |format| 92 | if item.update_attributes(params[str.underscore.singularize]) 93 | flash[:notice] = str.singularize.camelize + ' was successfully updated.' 94 | format.html { redirect_to(item) } 95 | format.xml { head :ok } 96 | else 97 | format.html { render :action => "edit" } 98 | format.xml { render :xml => item.errors, :status => :unprocessable_entity } 99 | end 100 | end 101 | end 102 | end 103 | end 104 | --------------------------------------------------------------------------------