Changeset 889

Show
Ignore:
Timestamp:
11/07/07 00:02:36 (1 year ago)
Author:
wyca..@gmail.com
Message:

rake dm:db:automigrate and some fixes to the resource controller

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/merb_datamapper/datamapper_generators/resource_controller/resource_controller_generator.rb

    r825 r889  
    55 
    66  def initialize(*args) 
     7    puts args.inspect 
    78    runtime_options = args.last.is_a?(Hash) ? args.pop : {} 
    89    name, *actions = args.flatten 
    910    runtime_options[:actions] = %w[index show new edit] 
    1011    runtime_options[:test_stub_generator] = "merb_controller_test" 
    11     super( [name], runtime_options ) 
     12    super( [name.pluralize], runtime_options ) 
    1213  end 
    1314 
  • plugins/merb_datamapper/datamapper_generators/resource_controller/templates/controller.rb

    r869 r889  
    11<% klass = class_name.singularize -%> 
    22<% ivar = class_name.snake_case.singularize -%> 
    3 class <%= class_name %> < Application 
     3class <%= class_name.pluralize %> < Application 
    44  provides :xml, :js, :yaml 
    55   
    66  def index 
    7     @<%= ivar %>s = <%= klass %>.all 
    8     render @<%= ivar %>s 
     7    @<%= ivar.pluralize %> = <%= klass %>.all 
     8    render @<%= ivar.pluralize %> 
    99  end 
    1010   
    1111  def show(id) 
    1212    @<%= ivar %> = <%= klass %>[id] 
     13    raise BadRequest unless @<%= ivar %> 
    1314    render @<%= ivar %> 
    1415  end 
    1516   
    16   def new(<%= ivar %>) 
     17  def new 
    1718    only_provides :html 
    18     @<%= ivar %> = <%= klass %>.new(<%= ivar %>) 
     19    @<%= ivar %> = <%= klass %>.new 
    1920    render @<%= ivar %> 
    2021  end 
    2122   
    2223  def create(<%= ivar %>) 
    23     @<%= ivar %> = <%= klass %>.new(
     24    @<%= ivar %> = <%= klass %>.new(<%= ivar %>
    2425    if @<%= ivar %>.save 
    2526      redirect url(:<%= ivar %>, @<%= ivar %>) 
     
    2930  end 
    3031   
    31   def edit 
     32  def edit(id) 
    3233    only_provides :html 
    33     @<%= ivar %> = <%= klass %>.find(params[:id]) 
     34    @<%= ivar %> = <%= klass %>[id] 
     35    raise BadRequest unless @<%= ivar %> 
    3436    render 
    3537  end 
     
    3739  def update(id, <%= ivar %>) 
    3840    @<%= ivar %> = <%= klass %>[id] 
     41    raise BadRequest unless @<%= ivar %> 
    3942    if @<%= ivar %>.update_attributes(<%= ivar %>) 
    4043      redirect url(:<%= ivar %>, @<%= ivar %>) 
     
    4649  def destroy(id) 
    4750    @<%= ivar %> = <%= klass %>[id] 
     51    raise BadRequest unless @<%= ivar %> 
    4852    if @<%= ivar %>.destroy! 
    49       redirect url(:<%= ivar %>s
     53      redirect url(:<%= ivar.pluralize %>
    5054    else 
    5155      raise BadRequest 
  • plugins/merb_datamapper/datamapper_generators/resource_controller/templates/helper.rb

    r825 r889  
    11module Merb 
    2 module <%= class_name %>Helper 
     2module <%= class_name.pluralize %>Helper 
    33   
    44  end 
  • plugins/merb_datamapper/lib/merb/orms/data_mapper/tasks/databases.rb

    r705 r889  
    33namespace :dm do 
    44  namespace :db do 
    5     desc "Perform migration using migrations in schema/migrations
    6     task :migrate => :merb_env do 
    7       #Sequel::Migrator.apply(Merb::Orms::Sequel.connect, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil) 
     5    desc "Perform automigration
     6    task :automigrate => :merb_env do 
     7      DataMapper::Base.auto_migrate! 
    88    end 
    99  end