Hi all, I would like to create a very simple form with RoR similar to this one in ASP.Net: http://quickstarts.asp.net/QuickStartv20/aspnet/samples/ctrlref/standard/TextBox/TextBox1_vb.aspx I my RoR project I want to add a Greeter class like this one: class Greeter def initialize(name = "World") @name = name end def say_hi puts "Hi #{@name}!" end def say_bye puts "Bye #{@name}, come back soon." end end my form will have two buttons one for "Hi!" and the other for "Bye!", a text box to enter a name, and a label to display the whole message. So if the user enters "Joe" and clicks the button "Hi", the label will display "Hi Joe" How do I create a Viewer that instantiates the class Greeter, and shows a message after the user click on a button. In a ASP.Net project in the code behind the button, on the click event I will have to add something like this: g = Greeter.new(<value entered on the text box>) <label> = g.say_hi How can I do it in RoR. I am interesed in the controller and viewer(s). thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Help!!! Where can I find information about how to add submit buttons to a form? thanks Jose Pepe wrote:> Hi all, > > I would like to create a very simple form with RoR similar to this one > in ASP.Net: > http://quickstarts.asp.net/QuickStartv20/aspnet/samples/ctrlref/standard/TextBox/TextBox1_vb.aspx > > > I my RoR project I want to add a Greeter class like this one: > class Greeter > def initialize(name = "World") > @name = name > end > def say_hi > puts "Hi #{@name}!" > end > def say_bye > puts "Bye #{@name}, come back soon." > end > end > > my form will have two buttons one for "Hi!" and the other for "Bye!", a > text box to enter a name, and a label to display the whole message. So > if the user enters "Joe" and clicks the button "Hi", the label will > display "Hi Joe" > > How do I create a Viewer that instantiates the class Greeter, and shows > a message after the user click on a button. > > In a ASP.Net project in the code behind the button, on the click event I > will have to add something like this: > > g = Greeter.new(<value entered on the text box>) > > <label> = g.say_hi > > How can I do it in RoR. I am interesed in the controller and viewer(s). > > thanks-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Jose, Do you want to add "buttons"? Or "a button"? The former is not allowed re: the W3C HTML spec. Rails shows you how to do the latter when you generate scaffolding for an app. Check out, for example, the new.rhtml view. hth, Bill ----- Original Message ----- From: "Jose Pepe" <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> Sent: Monday, October 02, 2006 7:55 AM Subject: [Rails] Re: How to create a very simple form> > Help!!! > > Where can I find information about how to add submit buttons to a form? > > thanks > > > > > Jose Pepe wrote: >> Hi all, >> >> I would like to create a very simple form with RoR similar to this one >> in ASP.Net: >> http://quickstarts.asp.net/QuickStartv20/aspnet/samples/ctrlref/standard/TextBox/TextBox1_vb.aspx >> >> >> I my RoR project I want to add a Greeter class like this one: >> class Greeter >> def initialize(name = "World") >> @name = name >> end >> def say_hi >> puts "Hi #{@name}!" >> end >> def say_bye >> puts "Bye #{@name}, come back soon." >> end >> end >> >> my form will have two buttons one for "Hi!" and the other for "Bye!", a >> text box to enter a name, and a label to display the whole message. So >> if the user enters "Joe" and clicks the button "Hi", the label will >> display "Hi Joe" >> >> How do I create a Viewer that instantiates the class Greeter, and shows >> a message after the user click on a button. >> >> In a ASP.Net project in the code behind the button, on the click event I >> will have to add something like this: >> >> g = Greeter.new(<value entered on the text box>) >> >> <label> = g.say_hi >> >> How can I do it in RoR. I am interesed in the controller and viewer(s). >> >> thanks > > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill To make it simpe lest say that I want to create a form with only on button, and a text box. Whe the user enters his/her name in the text box, and clicks the button, a message says "Hello X" I am just learning and looking for a very simple example without any database access. Where can I get any inforation about that? thanks Walton wrote:> Hi Jose, > > Do you want to add "buttons"? Or "a button"? > > The former is not allowed re: the W3C HTML spec. Rails shows you how to > do > the latter when you generate scaffolding for an app. Check out, for > example, the new.rhtml view. > > hth, > Bill > > ----- Original Message ----- > From: "Jose Pepe" <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > To: <rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > Sent: Monday, October 02, 2006 7:55 AM > Subject: [Rails] Re: How to create a very simple form-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
hi again I would like to convert to Ror this HTML folr: <body> <form name="form1" method="post" action=""> <p>Enter Your Name: <input name="textName" type="text" id="textName"> </p> <p><label>This is a label</label> </p> <p> <input name="btnHello" type="submit" id="btnHello" value="Hello!!"> </p> </form> </body> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Jose Pepe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > hi again > > I would like to convert to Ror this HTML folr: > <body> > <form name="form1" method="post" action=""> > <p>Enter Your Name: > <input name="textName" type="text" id="textName"> > </p> > <p><label>This is a label</label> </p> > <p> > <input name="btnHello" type="submit" id="btnHello" value="Hello!!"> > > </p> > </form> > </body> > >All you really need to do is to use a "railsy" form tag and set a value for the label: <%= start_form_tag :controller=>''test'', :action=>''say_hello'' %> <p>Enter your Name ... <label><%= @message %></label> </p> <%= end_form_tag %> This will render a <form action="/test/say_hello" ...> form tag, which will then get routed to your test_controller, which you create like this: ruby script/generate controller test and then you add a method say_hello: class TestController < ApplicationController def say_hello @message= "Hello " + params[:textName] end end This assigns a string to the @message instance variable of the controlle,r which then gets rendered in the view inside the label. I''d also recommend reading a few RoR tutorials to get your head around the MVC pattern as implemented in Rails. Without understanding what MVC means and how it works, you won''t get very far with Rails. Cheers, Max --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Max Adding an initialize method on the class TestController: class TestController < ApplicationController def initialize(name = "World") @name = name end def say_hi @message="Hi #{@name}!" end def say_bye @message="Bye #{@name}, come back soon." end end Do I need to replace the action ":action=>''say_hello''" by somethig like :action=>''initialize''? how do I get the say_hi method? Thank you Muermann wrote:> On 10/3/06, Jose Pepe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> <p> >> <input name="btnHello" type="submit" id="btnHello" value="Hello!!"> >> >> </p> >> </form> >> </body> >> >> > > All you really need to do is to use a "railsy" form tag and set a > value for the label: > > <%= start_form_tag :controller=>''test'', :action=>''say_hello'' %> > <p>Enter your Name > ... > <label><%= @message %></label> > </p> > <%= end_form_tag %> > > This will render a <form action="/test/say_hello" ...> form tag, which > will then get routed to your test_controller, which you create like > this: > > ruby script/generate controller test > > and then you add a method say_hello: > > class TestController < ApplicationController > def say_hello > @message= "Hello " + params[:textName] > end > end > > This assigns a string to the @message instance variable of the > controlle,r which then gets rendered in the view inside the label. > > I''d also recommend reading a few RoR tutorials to get your head around > the MVC pattern as implemented in Rails. Without understanding what > MVC means and how it works, you won''t get very far with Rails. > > Cheers, > Max-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Jose Pepe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Max > > Adding an initialize method on the class TestController: > > class TestController < ApplicationController > def initialize(name = "World") > @name = name > end > def say_hi > @message="Hi #{@name}!" > end > def say_bye > @message="Bye #{@name}, come back soon." > end > end > > > Do I need to replace the action ":action=>''say_hello''" by somethig like > :action=>''initialize''? how do I get the say_hi method? >"initialize" is the name for the constructor in ruby. You should not really need to implement a constructor for what you are doing, and you should definitely not call "initialize" as an action from your view. When a request comes in, rails will execute the method corresponding to the action name, so to just call say_hi, you can use :action=>''say_hi''. As you want to have different behaviour depending on which button was pressed, you can use the fact that the browser will send the value of the submit button that was used to submit the form. Print out the contents of the params array as the first statement in your action (p params) and see if you can find the button in there. From theree, it is easy enough to write an if statement that - based on the existence of a specific button value in the params - sets the message to the correct one. Give it a try and let me know if you get stuck. Cheers, Max --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Max, I am gettng an error message: can''t convert nil into string here is my controller: class GreetController < ApplicationController def say_hi @message= "Hello " + params[:textName] end end and my viewer <html> <head> <title> Hello!!!</title> </head> <body> <%= start_form_tag :controller=>''greet'', :action=>''say_hi'' %> <p>Enter Your Name: <%= text_field_tag :textName, :size=> 20 %> </p><p> <label><%= @message %></label> </p> <p> <%= submit_tag( "Hello") %> </p> <%= end_form_tag %> </body> </html> What is wrong? Muermann wrote:> On 10/3/06, Jose Pepe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> @message="Hi #{@name}!" >> end >> def say_bye >> @message="Bye #{@name}, come back soon." >> end >> end >> >> >> Do I need to replace the action ":action=>''say_hello''" by somethig like >> :action=>''initialize''? how do I get the say_hi method? >> > > "initialize" is the name for the constructor in ruby. You should not > really need to implement a constructor for what you are doing, and you > should definitely not call "initialize" as an action from your view. > > When a request comes in, rails will execute the method corresponding > to the action name, so to just call say_hi, you can use > :action=>''say_hi''. > > As you want to have different behaviour depending on which button was > pressed, you can use the fact that the browser will send the value of > the submit button that was used to submit the form. > > Print out the contents of the params array as the first statement in > your action (p params) and see if you can find the button in there. > From theree, it is easy enough to write an if statement that - based > on the existence of a specific button value in the params - sets the > message to the correct one. > > Give it a try and let me know if you get stuck. > > Cheers, > Max-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
here is the whole error message: TypeError in GreetController#say_hi can''t convert nil into String RAILS_ROOT: script/../config/.. Application Trace | Framework Trace | Full Trace app/controllers/greet_controller.rb:3:in `+'' app/controllers/greet_controller.rb:3:in `say_hi'' -e:4:in `load'' -e:4 Jose Pepe wrote:> Max, > > I am gettng an error message: > > can''t convert nil into string > > here is my controller: > class GreetController < ApplicationController > def say_hi > @message= "Hello " + params[:textName] > end > end > > > and my viewer > <html> > <head> > <title> Hello!!!</title> > </head> > <body> > <%= start_form_tag :controller=>''greet'', :action=>''say_hi'' %> > <p>Enter Your Name: > <%= text_field_tag :textName, :size=> 20 %> > </p><p> > <label><%= @message %></label> > </p> > <p> > <%= submit_tag( "Hello") %> > </p> > <%= end_form_tag %> > </body> > </html> > > What is wrong? > > Muermann wrote: >> On 10/3/06, Jose Pepe <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >>> @message="Hi #{@name}!" >>> end >>> def say_bye >>> @message="Bye #{@name}, come back soon." >>> end >>> end >>> >>> >>> Do I need to replace the action ":action=>''say_hello''" by somethig like >>> :action=>''initialize''? how do I get the say_hi method? >>> >> >> "initialize" is the name for the constructor in ruby. You should not >> really need to implement a constructor for what you are doing, and you >> should definitely not call "initialize" as an action from your view. >> >> When a request comes in, rails will execute the method corresponding >> to the action name, so to just call say_hi, you can use >> :action=>''say_hi''. >> >> As you want to have different behaviour depending on which button was >> pressed, you can use the fact that the browser will send the value of >> the submit button that was used to submit the form. >> >> Print out the contents of the params array as the first statement in >> your action (p params) and see if you can find the button in there. >> From theree, it is easy enough to write an if statement that - based >> on the existence of a specific button value in the params - sets the >> message to the correct one. >> >> Give it a try and let me know if you get stuck. >> >> Cheers, >> Max-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---