Skip to content
Browse files

model generator

  • Loading branch information...
1 parent 6854b0b commit 80efc53ecb45d7812ba29da7d892d632bed7274a @barthezslavik barthezslavik committed Dec 27, 2011
View
3 Gemfile
@@ -40,8 +40,6 @@ gem 'memcache-client'
#gem 'postmark-rails'
group :development do
- gem 'ruby-debug19', :require => 'ruby-debug'
-
# for devise views generator
gem 'hpricot'
gem 'ruby_parser'
@@ -72,5 +70,4 @@ group :test do
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'spork', '~> 0.9.0.rc'
-
end
View
15 Gemfile.lock
@@ -31,7 +31,6 @@ GEM
activesupport (3.1.1)
multi_json (~> 1.0)
addressable (2.2.6)
- archive-tar-minitar (0.5.2)
arel (2.2.1)
autotest (4.4.6)
ZenTest (>= 4.4.1)
@@ -61,7 +60,6 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.1.3)
- columnize (0.3.5)
compass (0.11.5)
chunky_png (~> 1.2)
fssm (>= 0.2.7)
@@ -143,8 +141,6 @@ GEM
configuration (>= 0.0.5)
rake (>= 0.8.1)
libnotify (0.6.0)
- linecache19 (0.5.12)
- ruby_core_source (>= 0.1.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
@@ -233,17 +229,7 @@ GEM
activesupport (~> 3.0)
railties (~> 3.0)
rspec (~> 2.7.0)
- ruby-debug-base19 (0.11.25)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby_core_source (>= 0.1.4)
- ruby-debug19 (0.11.6)
- columnize (>= 0.3.1)
- linecache19 (>= 0.5.11)
- ruby-debug-base19 (>= 0.11.19)
ruby-progressbar (0.0.10)
- ruby_core_source (0.1.5)
- archive-tar-minitar (>= 0.5.2)
ruby_parser (2.3.1)
sexp_processor (~> 3.0)
rubyzip (0.9.5)
@@ -326,7 +312,6 @@ DEPENDENCIES
rails (= 3.1.1)
rb-inotify
rspec-rails (>= 2.6.0)
- ruby-debug19
ruby_parser
russian
sass-rails (~> 3.1.0.rc)
View
32 app/controllers/Proposals_controller.rb
@@ -0,0 +1,32 @@
+class ProposalsController < ApplicationController
+
+ def index
+ @Proposals = Proposal.all
+ end
+
+ def show
+ @Proposals = Proposal.find(params[:id])
+ end
+
+ def new
+ @Proposals = Proposal.new
+ end
+
+ def edit
+ @Proposals = Proposal.find(params[:id])
+ end
+
+ def create
+ @Proposals = Proposal.new(params[:proposal])
+ end
+
+ def update
+ @Proposals = Proposal.find(params[:id])
+ end
+
+ def destroy
+ @Proposals = Proposal.find(params[:id])
+ @Proposals.destroy
+ end
+
+end
View
14 app/controllers/proposals_controller.rb
@@ -5,28 +5,28 @@ def index
end
def show
- @proposal = Proposal.find(params[:id])
+ @proposals = Proposal.find(params[:id])
end
def new
- @proposal = Proposal.new
+ @proposals = Proposal.new
end
def edit
- @proposal = Proposal.find(params[:id])
+ @proposals = Proposal.find(params[:id])
end
def create
- @proposal = Proposal.new(params[:proposal])
+ @proposals = Proposal.new(params[:proposal])
end
def update
- @proposal = Proposal.find(params[:id])
+ @proposals = Proposal.find(params[:id])
end
def destroy
- @proposal = Proposal.find(params[:id])
- @proposal.destroy
+ @proposals = Proposal.find(params[:id])
+ @proposals.destroy
end
end
View
5 app/models/proposal.rb
@@ -1,3 +1,8 @@
class Proposal
include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :title, type: String
+ field :content, type: String
+
end
View
2 app/views/layouts/application.html.haml
@@ -24,7 +24,7 @@
.main
=link_to "Публикации", "/"
=link_to "Пользователи", "/users"
- =link_to "Предложения", "/users"
+ =link_to "Предложения", "/proposals"
%br
#loop.list.clear
#tab1.tabberlive
View
2 app/views/proposals/index.html.haml
@@ -0,0 +1,2 @@
+= render @proposals
+= paginate @proposals if @proposals.exists?
View
22 lib/generators/ria/ria_generator.rb
@@ -7,21 +7,25 @@ def initial
class RiaGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
- argument :name, :type => :string, :default => "proposal"
+ argument :name, :type => :string
+ argument :args_all, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
#class_option :stylesheet, :type => :boolean, :default => true, :description => "Include stylesheet file"
+ def initialize(*args, &block)
+ super
+ @fields = []
+ args_all.each do |arg|
+ @fields << arg if arg.include?(':')
+ end
+ end
+
def generate_layout
template "_model.html.haml", "app/views/#{plural_name}/_#{file_name}.html.haml"
template "index.js.haml", "app/views/#{plural_name}/index.js.haml"
+ template "index.html.haml", "app/views/#{plural_name}/index.html.haml"
template "controller.rb", "app/controllers/#{plural_name}_controller.rb"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #copy_file "index.html.haml", "app/controllers/#{file_name}/index.html.haml"
- #template "layout.html.erb", "app/#{file_name}/views/index.html.haml"
+ template "model.rb", "app/models/#{file_name}.rb"
+ route "resources :#{plural_name}"
end
private
View
2 lib/generators/ria/templates/index.html.haml
@@ -0,0 +1,2 @@
+= render @<%=plural_name%>
+= paginate @<%=plural_name%> if @<%=plural_name%>.exists?
View
7 lib/generators/ria/templates/model.rb
@@ -0,0 +1,7 @@
+class <%=file_name.capitalize%>
+ include Mongoid::Document
+ include Mongoid::Timestamps
+ <% @fields.each do |field| p = field.split(":") %>
+ <%="field :#{p.first}, type: #{p.last.capitalize}" if p.last == 'string' %><%="field :#{p.first}, type: #{p.last.capitalize}, default: \"0\"" if p.last == 'integer' %><%="field :#{p.first}, type: #{p.last.capitalize}, default: []" if p.last == 'array' %><% end %>
+
+end

0 comments on commit 80efc53

Please sign in to comment.
Something went wrong with that request. Please try again.