BasicObject
Lookup missing generators using const_missing. This allows any generator to reference another without having to know its location: RubyGems, ~/.rails/generators, and RAILS_ROOT/generators.
# File lib/rails_generator/lookup.rb, line 10 def lookup_missing_generator(class_id) if md = /(.+)Generator$/.match(class_id.to_s) name = md.captures.first.demodulize.underscore Rails::Generator::Base.lookup(name).klass else const_missing_before_generators(class_id) end end
reference the global "app" instance, created on demand. To recreate the instance, pass a non-false value as the parameter.
# File lib/console_app.rb, line 9 def app(create=false) @app_integration_instance = nil if create @app_integration_instance ||= new_session do |sess| sess.host! "www.example.com" end end
POST /<%= table_name %>.xml
# File lib/rails_generator/generators/components/scaffold/templates/controller.rb, line 42 def create @<% file_name %> = <% class_name %>.new(params[:<%= file_name %>]) respond_to do |format| if @<% file_name %>.save format.html { redirect_to(@<%= file_name %>, :notice => '<%= class_name %> was successfully created.') } format.xml { render :xml => @<% file_name %>, :status => :created, :location => @<% file_name %> } else format.html { render :action => "new" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end end end
# File lib/test_help.rb, line 24 def create_fixtures(*table_names, &block) Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block) end
DELETE /<%= table_name %>/1 DELETE /<%= table_name %>/1.xml
# File lib/rails_generator/generators/components/scaffold/templates/controller.rb, line 74 def destroy @<% file_name %> = <% class_name %>.find(params[:id]) @<%= file_name %>.destroy respond_to do |format| format.html { redirect_to(<% table_name %>_url) } format.xml { head :ok } end end end
# File lib/rails_generator/generators/components/scaffold/templates/controller.rb, line 36 def edit @<% file_name %> = <% class_name %>.find(params[:id]) end # POST /<%= table_name %> # POST /<%= table_name %>.xml def create @<% file_name %> = <% class_name %>.new(params[:<%= file_name %>]) respond_to do |format| if @<% file_name %>.save format.html { redirect_to(@<%= file_name %>, :notice => '<%= class_name %> was successfully created.') } format.xml { render :xml => @<% file_name %>, :status => :created, :location => @<% file_name %> } else format.html { render :action => "new" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end end end # PUT /<%= table_name %>/1 # PUT /<%= table_name %>/1.xml def update @<% file_name %> = <% class_name %>.find(params[:id]) respond_to do |format| if @<%= file_name %>.update_attributes(params[:<= file_name %>]) format.html { redirect_to(@<% file_name %>, :notice => '<%= class_name %> was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end end
# File lib/commands/dbconsole.rb, line 33 def find_cmd(*commands) dirs_on_path = ENV['PATH'].to_s.split(File::PATH_SEPARATOR) commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/ full_path_command = nil found = commands.detect do |cmd| dir = dirs_on_path.detect do |path| full_path_command = File.join(path, cmd) File.executable? full_path_command end end found ? full_path_command : abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.") end
# File lib/console_with_helpers.rb, line 1 def helper @helper ||= ApplicationController.helpers end
GET /<%= table_name %>.xml
# File lib/rails_generator/generators/components/scaffold/templates/controller.rb, line 4 def index @<% table_name %> = <% class_name %>.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @<% table_name %> } end end # GET /<%= table_name %>/1 # GET /<% table_name %>/1.xml def show @<%= file_name %> = <% class_name %>.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @<% file_name %> } end end # GET /<%= table_name %>/new # GET /<% table_name %>/new.xml def new @<%= file_name %> = <% class_name %>.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @<% file_name %> } end end # GET /<%= table_name %>/1/dit def edit @<% file_name %> = <% class_name %>.find(params[:id]) end # POST /<%= table_name %> # POST /<%= table_name %>.xml def create @<% file_name %> = <% class_name %>.new(params[:<%= file_name %>]) respond_to do |format| if @<% file_name %>.save format.html { redirect_to(@<%= file_name %>, :notice => '<%= class_name %> was successfully created.') } format.xml { render :xml => @<% file_name %>, :status => :created, :location => @<% file_name %> } else format.html { render :action => "new" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end end end # PUT /<%= table_name %>/1 # PUT /<%= table_name %>/1.xml def update @<% file_name %> = <% class_name %>.find(params[:id]) respond_to do |format| if @<%= file_name %>.update_attributes(params[:<= file_name %>]) format.html { redirect_to(@<% file_name %>, :notice => '<%= class_name %> was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end end end
# File lib/commands/ncgi/listener, line 7 def message(s) $stderr.puts "listener: #{s}" if ENV && ENV["DEBUG_GATEWAY"] end
create a new session. If a block is given, the new session will be yielded to the block before being returned.
# File lib/console_app.rb, line 18 def new_session session = ActionController::Integration::Session.new yield session if block_given? session end
reloads the environment
# File lib/console_app.rb, line 25 def reload! puts "Reloading..." Dispatcher.cleanup_application Dispatcher.reload_application true end
PUT /<%= table_name %>/1 PUT /<%= table_name %>/1.xml
# File lib/rails_generator/generators/components/scaffold/templates/controller.rb, line 58 def update @<% file_name %> = <% class_name %>.find(params[:id]) respond_to do |format| if @<%= file_name %>.update_attributes(params[:<= file_name %>]) format.html { redirect_to(@<% file_name %>, :notice => '<%= class_name %> was successfully updated.') } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @<% file_name %>.errors, :status => :unprocessable_entity } end
Generated with the Darkfish Rdoc Generator 2.