Arc Forumnew | comments | leaders | submitlogin
5 points by lojic 6131 days ago | link | parent

Here's a first draft in Rails that doesn't use any template files.

  class HomeController < ApplicationController
    def first
      if request.get?
        aform 'first', [input('foo'), submit]
      else
        session[:foo] = params[:foo]
        wlink 'third', 'click here'
      end
    end

    def third
      pr "you said: #{session[:foo]}"
    end
  end


6 points by lojic 6130 days ago | link

A small example is fine, but wouldn't it be better if it at least did some basic validation? How does the Arc example change if you enforce only alphanumeric characters in the input field?

  class HomeController < ApplicationController
    def first
      if request.get?
        aform 'first', [input('foo'), submit]
      else
        if params[:foo] && params[:foo] =~ /[A-Za-z0-9]/ 
          session[:foo] = params[:foo]
          wlink 'third', 'click here'
        else
          aform 'first', ["Please enter an alphanumeric string", input('foo'), submit]
        end
      end
    end

    def third
      pr "you said: #{session[:foo]}"
    end
  end
Of course, we'll then want to allow the designers to modify the presentation, and allow the copy writers to add compelling text, etc. So, it seems like a template system is the way to go, but maybe someone has a better idea.

-----

3 points by lojic 6131 days ago | link

I can see pros/cons of a template based approach vs. generating everything. I do find the separation of templates from code to be very beneficial since I haven't been able to get to the point of controlling 100% of the presentation via CSS alone - sometimes a simple structural change in a template file is less intrusive than modifying code.

Also, I wonder about the overhead of continuation based approaches with higher volumes.

-----

4 points by akkartik 6129 days ago | link

> I haven't been able to get to the point of controlling 100% of the presentation via CSS alone..

I think that's the real reason PG uses tables.

-----

2 points by lojic 6129 days ago | link

BTW, this is working code. I just had to add the following functions to app/controllers/application.rb:

aform, input, pr, submit, wlink

all one liners except for aform which is 3

-----