lib/generators/scaffold_controller/templates/controller.rb in nested_scaffold-0.2.0 vs lib/generators/scaffold_controller/templates/controller.rb in nested_scaffold-0.2.1

- old
+ new

@@ -1,84 +1,90 @@ class <%= controller_class_name %>Controller < ApplicationController # GET <%= plural_nested_parent_name %>/1/<%= plural_name %> - # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>.xml + # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>.json def index - <%= "@#{plural_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{plural_name} = @#{nested_parent_name}.#{plural_name}" %> respond_to do |format| format.html # index.html.erb - format.xml { render :xml => @<%= plural_name %> } + format.json { render :json => @<%= plural_name %> } end end # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1 - # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml + # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.json def show - <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.find(params[:id])" %> respond_to do |format| format.html # show.html.erb - format.xml { render :xml => @<%= singular_name %> } + format.json { render :json => @<%= singular_name %> } end end # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/new - # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/new.xml + # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/new.json def new - <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.build" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.build" %> respond_to do |format| format.html # new.html.erb - format.xml { render :xml => @<%= singular_name %> } + format.json { render :json => @<%= singular_name %> } end end # GET <%= plural_nested_parent_name %>/1/<%= plural_name %>/1/edit def edit - <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.find(params[:id])" %> end # POST <%= plural_nested_parent_name %>/1/<%= plural_name %> - # POST <%= plural_nested_parent_name %>/1/<%= plural_name %>.xml + # POST <%= plural_nested_parent_name %>/1/<%= plural_name %>.json def create - <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.build(params[:#{singular_name}])" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.build(params[:#{singular_name}])" %> respond_to do |format| if @<%= singular_name %>.save format.html { redirect_to([@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>], :notice => '<%= human_name %> was successfully created.') } - format.xml { render :xml => @<%= singular_name %>, :status => :created, :location => [@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>] } + format.json { render :json => @<%= singular_name %>, :status => :created, :location => [@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>] } else format.html { render :action => "new" } - format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity } + format.json { render :json => @<%= singular_name %>.errors, :status => :unprocessable_entity } end end end # PUT <%= plural_nested_parent_name %>/1/<%= plural_name %>/1 - # PUT <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml + # PUT <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.json def update - <%= "@#{singular_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}]).#{plural_name}.find(params[:id])" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.find(params[:id])" %> respond_to do |format| if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>]) format.html { redirect_to([@<%= singular_name %>.<%= nested_parent_name %>, @<%= singular_name %>], :notice => '<%= human_name %> was successfully updated.') } - format.xml { head :ok } + format.json { head :ok } else format.html { render :action => "edit" } - format.xml { render :xml => @<%= singular_name %>.errors, :status => :unprocessable_entity } + format.json { render :json => @<%= singular_name %>.errors, :status => :unprocessable_entity } end end end # DELETE <%= plural_nested_parent_name %>/1/<%= plural_name %>/1 - # DELETE <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.xml + # DELETE <%= plural_nested_parent_name %>/1/<%= plural_name %>/1.json def destroy - <%= "#{nested_parent_name} = #{nested_parent_class_name}.find(params[:#{nested_parent_id}])" %> - <%= "@#{singular_name} = #{nested_parent_name}.#{plural_name}.find(params[:id])" %> + @<%= nested_parent_name %> = <%= orm_class.find(nested_parent_class_name, "params[:#{nested_parent_id}]") %> + <%= "@#{singular_name} = @#{nested_parent_name}.#{plural_name}.find(params[:id])" %> @<%= singular_name %>.destroy respond_to do |format| format.html { redirect_to <%= nested_parent_name %>_<%= index_helper %>_url(<%= nested_parent_name %>) } - format.xml { head :ok } + format.json { head :ok } end end end