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? And how is it sent along? Must the post method have a certain argument? If somebody could answer my questions it would be extremely appreciated. -Waffles -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20110829/0036e722/attachment.html>
That''s great that you''re learning a new language. I really hope you have tons of fun and make a whole lot of neat stuff. Keep us posted, kay? On forms: The :action property is optional - if you omit it, it''ll submit the form to the same URL you''re currently on in your web browser. You use R() in the action just like you''d use it on an a(:href => R(?)) link. The thing about PageX, is that it takes one thing with it, the X - so it''s urls look like /page/something/, and you kind of need to tell it what the something is. If you make a controller called, say, class MyCoolStuff; then you can just :action towards R(MyCoolStuff) and that''ll be that. I hope that clears things up a bit. ? Bluebie On 30/08/2011, at 1:47 PM, Anonymous Waffles 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? > > And how is it sent along? Must the post method have a certain argument? > > If somebody could answer my questions it would be extremely appreciated. > > -Waffles _______________________________________________ > Camping-list mailing list > Camping-list at rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20110830/e3d86376/attachment.html>
On Mon, Aug 29, 2011 at 8:47 PM, Anonymous Waffles < theonetruewaffles at 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/camping-list/attachments/20110829/c64c3783/attachment.html>