class ExamplesController < ApplicationController layout 'data_layout' before_filter :authorize, :only => [ :new, :more_properties] # GET /examples # GET /examples.xml def index @examples = Example.find_by_sql("SELECT * FROM examples ORDER BY language, sentenceNumber") respond_to do |format| format.html # index.html.erb format.xml { render :xml => @examples } end end # GET /examples/1 # GET /examples/1.xml def show @example = Example.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @example } end end # GET /examples/new # GET /examples/new.xml def new JILLIAN: I suspect it is enough to present only the properties JILLIAN: expressed at the language level, not their values. JILLIAN: This seems to require getting the language earlier and then JILLIAN: inserting it in this @properties select statement. JILLIAN: You already do this at the line &&&& @example = Example.new @properties = Language.find_by_sql("SELECT DISTINCT property FROM languages WHERE property NOT LIKE '%latlong%' AND property NOT LIKE '%ISO%' ORDER BY property") @languages = Language.find_by_sql("SELECT DISTINCT language FROM languages") respond_to do |format| format.html # new.html.erb format.xml { render :xml => @example } end end # GET /examples/1/edit def edit @example = Example.find(params[:id]) end # POST /examples # POST /examples.xml def create if(params[:element]!= nil ) #This is a very crude way of making sure that the response is recieved from the more_properties page example = Example.find(params[:element][:id]) properties=[] params[:property].keys.each do |key| properties< example.language, :etype => "normal", :sentenceNumber => example.sentenceNumber, :property => p, :value => values[p], :author=> params[:element][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) #end end respond_to do |format| format.html { redirect_to(examples_path) } end else # At some point, we want to change this to just select the max sentenceNumber num = Example.find_by_sql("SELECT DISTINCT sentenceNumber FROM examples WHERE language LIKE \'" + params[:example][:language] + "\' " + "ORDER BY sentenceNumber") num.sort!{|n1, n2| n1.sentenceNumber.to_i <=> n2.sentenceNumber.to_i} sentenceNumber = "" if num == [] sentenceNumber = "1" else sentenceNumber = (num[num.size - 1].sentenceNumber.to_i + 1).to_s end @example = Example.new(:language => params[:example][:language], :etype => "normal", :sentenceNumber => sentenceNumber, :property => params[:example][:property], :value => params[:example][:value], :author => params[:example][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) @example_words = Example.new(:language => params[:example][:language], :etype => "normal", :sentenceNumber => sentenceNumber, :property => "words", :value => params[:example][:words], :author => params[:example][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) @example_gloss = Example.new(:language => params[:example][:language], :etype => "normal", :sentenceNumber => sentenceNumber, :property => "gloss", :value => params[:example][:gloss], :author => params[:example][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) @example_translation = Example.new(:language => params[:example][:language], :etype => "normal", :sentenceNumber => sentenceNumber, :property => "translation", :value => params[:example][:translation], :author => params[:example][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) @example_comment = Example.new(:language => params[:example][:language], :etype => "normal", :sentenceNumber => sentenceNumber, :property => "comment", :value => params[:example][:comment], :author => params[:example][:author], :date => Time.now.strftime('%Y-%m-%d'), :time => Time.now) respond_to do |format| if @example.save @example_words.save @example_gloss.save @example_translation.save @example_comment.save flash[:notice] = 'Example was successfully created.' format.html { redirect_to(@example) } format.xml { render :xml => @example, :status => :created, :location => @example } else format.html { render :action => "new" } format.xml { render :xml => @example.errors, :status => :unprocessable_entity } end end end end # PUT /examples/1 # PUT /examples/1.xml def update @example = Example.find(params[:id]) respond_to do |format| if @example.update_attributes(params[:example]) flash[:notice] = 'Example was successfully updated.' format.html { redirect_to(@example) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @example.errors, :status => :unprocessable_entity } end end end # DELETE /examples/1 # DELETE /examples/1.xml def destroy @example = Example.find(params[:id]) @example.destroy respond_to do |format| format.html { redirect_to(examples_url) } format.xml { head :ok } end end JILLIAN: &&&&& def more_properties @element = Example.find(params[:id]) @properties = Language.find_by_sql("SELECT DISTINCT property FROM languages WHERE language LIKE'" + @element.language + "' ORDER BY property") @language = @element.language respond_to do |format| format.html # more_properties.html.erb end end end