Parent

Included Modules

Class/Module Index [+]

Quicksearch

Object

Public Class Methods

lookup_missing_generator(class_id) click to toggle source

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

Public Instance Methods

app(create=false) click to toggle source

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
create() click to toggle source

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
create_fixtures(*table_names, &block) click to toggle source
# File lib/test_help.rb, line 24
def create_fixtures(*table_names, &block)
  Fixtures.create_fixtures(ActiveSupport::TestCase.fixture_path, table_names, {}, &block)
end
destroy() click to toggle source

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
edit() click to toggle source
# 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
find_cmd(*commands) click to toggle source
# 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
helper() click to toggle source
# File lib/console_with_helpers.rb, line 1
def helper
  @helper ||= ApplicationController.helpers
end
index() click to toggle source

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
message(s) click to toggle source
# File lib/commands/ncgi/listener, line 7
def message(s)
  $stderr.puts "listener: #{s}" if ENV && ENV["DEBUG_GATEWAY"]
end
new_session() click to toggle source

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
reload!() click to toggle source

reloads the environment

# File lib/console_app.rb, line 25
def reload!
  puts "Reloading..."
  Dispatcher.cleanup_application
  Dispatcher.reload_application
  true
end
update() click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.