class <%= controller_class_name %>Controller < ApplicationController # GET /<%= table_name %> # GET /<%= table_name %>.xml def index @app_search.default 'id', 'desc' @app_search.sort 'id', '<%= plural_name %>.id' <% conditions_l = "" -%> <% conditions_r = "" -%> <% for attribute in attributes -%> <% reference_col = attribute.reference? ? "_id" : "" -%> @app_search.sort '<%= attribute.name %>', '<%= plural_name %>.<%= attribute.name %><%= reference_col %>' <% conditions_l += "#{plural_name}.#{attribute.name}#{reference_col} like ? or " -%> <% conditions_r += '@app_search.keyword, ' -%> <% end -%> <% conditions_l = conditions_l.slice(0, conditions_l.size - 3) -%> <% conditions_r = conditions_r.slice(0, conditions_r.size - 2) -%> alls = <%= class_name %>.all( # :include => [], :conditions => ["<%= conditions_l %>", <%= conditions_r %>], :order => @app_search.orderby ) session_set_ids(alls) page = alls.paginate(:page => params[:page], :per_page => PAGINATE_PER_PAGE); @<%= plural_name %> = page xmls = alls respond_to do |format| format.html # index.html.erb format.csv { send_data(xmls.to_csv(:instance => <%= class_name %>), :type => "text/csv") } # format.xml { send_data(xmls.to_xml, :type => "text/xml; charset=utf8;", :disposition => "attachement") } 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.csv { send_data(@<%= file_name %>.to_a.to_csv(:instance => <%= class_name %>), :type => "text/csv") } # format.xml { send_data(@<%= file_name %>.to_xml, :type => "text/xml; charset=utf8;", :disposition => "attachement") } end end # GET /<%= table_name %>/new # GET /<%= table_name %>/new.xml def new @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>]) end # GET /<%= table_name %>/1/edit def edit @<%= file_name %> = <%= class_name %>.find(params[:id]) @<%= file_name %>.attributes = params[:<%= file_name %>] end # POST /<%= table_name %> # POST /<%= table_name %>.xml def check @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>]) render :action => :new, :status => 400 and return unless @<%= file_name %>.valid? end # POST /<%= table_name %> # POST /<%= table_name %>.xml def create begin @<%= file_name %> = <%= class_name %>.new(params[:<%= file_name %>]) @<%= file_name %>.save! flash[:notice] = t(:success_created, :id => @<%= file_name %>.id) redirect_to(<%= table_name %>_url) rescue => e flash[:error] = t(:error_default, :message => e.message) render :action => :new end end # PUT /<%= table_name %>/1 # PUT /<%= table_name %>/1.xml def confirm @<%= file_name %> = <%= class_name %>.find(params[:id]) @<%= file_name %>.attributes = params[:<%= file_name %>] render :action => :edit, :status => 400 and return unless @<%= file_name %>.valid? end # PUT /<%= table_name %>/1 # PUT /<%= table_name %>/1.xml def update begin @<%= file_name %> = <%= class_name %>.find(params[:id]) @<%= file_name %>.update_attributes(params[:<%= file_name %>]) flash[:notice] = t(:success_updated, :id => @<%= file_name %>.id) redirect_to(<%= table_name %>_url) rescue => e flash[:error] = t(:error_default, :message => e.message) render :action => :edit end end # DELETE /<%= table_name %>/1 # DELETE /<%= table_name %>/1.xml def destroy begin @<%= file_name %> = <%= class_name %>.find(params[:id]) @<%= file_name %>.destroy Log.create(:user_id => session_get_user, :action => controller_name, :error => action_name + " " + params[:id]) flash[:notice] = t(:success_deleted, :id => @<%= file_name %>.id) redirect_to(<%= file_name %>s_url) rescue => e flash[:error] = t(:error_default, :message => e.message) render :action => :show end end end