On Mon, Aug 29, 2011 at 8:47 PM, Anonymous Waffles <
theonetruewaff...@gmail.com> wrote:

> Hello guys, I'm new to the Ruby, and especially to Camping. I've been
> having some difficulty because there aren't that many tutorials about
> Camping compared to other larger frameworks.
> I've been building some small stuff recently to learn about how it
> work, but I've puzzles as to how user input in a textbox is processed.
> Here's some code from the awfully short yet extremely informative
> Camping Book:
>
> module Nuts::Views
>  def edit
>   h1 @page.title
>   form :action => R(PageX, @page.title), :method => :post do
>     textarea @page.content, :name => :content,
>       :rows => 10, :cols => 50
>
>     br
>
>     input :type => :submit, :value => "Submit!"
>   end
>  end
>  end
>
> It's apparent that since the input is encased in the textarea block,
> it send the value when clicked. the :action says what class to send it
> to, and :method which method. *The docs say that the R() syntax is for
> creating a path. Could I simply use the name of a controller instead,
> if it's in the same Ruby file?*
>

No.  A form's action attribute requires a path or a URL.  Controllers are
not usually meaningful paths.  Therefore, you should continue to use the R()
function to generate paths.

An alternative to using the R() function would be to generate a path
yourself.

"/page/#{@page.title}"  <-- That would work, but I personally recommend
sticking to using the R() function.  It gives you the freedom to tweak the
URL structure of your web app with minimal pain.


And how is it sent along? Must the post method have a certain argument?
>

Let's pretend this is our PageX controller:

class PageX

  def get(title)
    @page = H.new
    @page.title = title
    render :page
  end

  def post(title)
    content = *@input.content*
    # do something with content and then...
    redirect R(PageX, title)
  end

end


When someone submits the form you made, the post() method of the PageX
controller will be run, and all the form variables will be in @input.

Hope that helps.

--beppu





PS:  A question for those who have deep Camping knowledge....  Since when
did Camping support "Simpler Routes" as described in
http://camping.rubyforge.org/book/02_getting_started.html ?

I had no idea until just a few minutes ago that capital "N" and "X" had a
special meaning in controller names.
_______________________________________________
Camping-list mailing list
Camping-list@rubyforge.org
http://rubyforge.org/mailman/listinfo/camping-list

Reply via email to