Hello people, rails noob here, I am trying to create an extremely simple addition application by having two text boxes allow users to put in any numbers, press a button, and get them added together. This is my first attempted application by myself, so I am probably making lots of simple mistakes. So far I have this in the view: <%= text_field_tag :number_one %> <%= text_field_tag :number_two %> I have tried to call params[:number_one], and params[:number_two] in my controller, but I get an error. A short bit of code showing what my controller should look like would be great thanks! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 25, 1:14 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So far I have this in the view: > > <%= text_field_tag :number_one %> > <%= text_field_tag :number_two %> > > I have tried to call params[:number_one], and params[:number_two] in > my controller, but I get an error.What error? Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Anytime I put params[:number_one] or two in my controller and start the server up I get this error on my page: undefined local variable or method `params'' for UserController:Class On Oct 25, 5:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 25, 1:14 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > So far I have this in the view: > > > <%= text_field_tag :number_one %> > > <%= text_field_tag :number_two %> > > > I have tried to call params[:number_one], and params[:number_two] in > > my controller, but I get an error. > > What error? > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Anytime I put params[:number_one] or two in my controller I get this error on my page: undefined local variable or method `params'' for ApplicationController:Class On Oct 25, 5:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 25, 1:14 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > So far I have this in the view: > > > <%= text_field_tag :number_one %> > > <%= text_field_tag :number_two %> > > > I have tried to call params[:number_one], and params[:number_two] in > > my controller, but I get an error. > > What error? > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok, so I figured out what was causing the error, I wasnt calling params[:number_one] in the right place. Fixing this took care of the error. Now I can call them in my controller like so: @a = params[:number_one].to_i @b = params[:number_one].to_i @sum = @a + @b But when I put numbers in my text boxes, it always shows 0. I even put this is my view: <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> And it also always shows 0. What am I doing wrong? On Oct 25, 9:18 pm, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Anytime I put params[:number_one] or two in my controller I get this > error on my page: > > undefined local variable or method `params'' for > ApplicationController:Class > > On Oct 25, 5:03 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Oct 25, 1:14 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > So far I have this in the view: > > > > <%= text_field_tag :number_one %> > > > <%= text_field_tag :number_two %> > > > > I have tried to call params[:number_one], and params[:number_two] in > > > my controller, but I get an error. > > > What error? > > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 26, 3:18 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, so I figured out what was causing the error, I wasnt calling > params[:number_one] in the right place. Fixing this took care of the > error. Now I can call them in my controller like so: > > @a = params[:number_one].to_i > @b = params[:number_one].to_i > @sum = @a + @b > > But when I put numbers in my text boxes, it always shows 0. I even put > this is my view: > > <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> > > And it also always shows 0. What am I doing wrong? >I''d check the development.log file to see what parameters are actually getting submitted. Fred -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It doesn''t say any numbers, the relevant log info just says it processed the GET and got the layout. On Oct 26, 4:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Oct 26, 3:18 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Ok, so I figured out what was causing the error, I wasnt calling > > params[:number_one] in the right place. Fixing this took care of the > > error. Now I can call them in my controller like so: > > > @a = params[:number_one].to_i > > @b = params[:number_one].to_i > > @sum = @a + @b > > > But when I put numbers in my text boxes, it always shows 0. I even put > > this is my view: > > > <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> > > > And it also always shows 0. What am I doing wrong? > > I''d check the development.log file to see what parameters are actually > getting submitted. > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 Oct, 20:56, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It doesn''t say any numbers, the relevant log info just says it > processed the GET and got the layout. >Sounds like the parameters aren''t getting sent What does the rest of the view with the form look like? Fred> On Oct 26, 4:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On Oct 26, 3:18 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Ok, so I figured out what was causing the error, I wasnt calling > > > params[:number_one] in the right place. Fixing this took care of the > > > error. Now I can call them in my controller like so: > > > > @a = params[:number_one].to_i > > > @b = params[:number_one].to_i > > > @sum = @a + @b > > > > But when I put numbers in my text boxes, it always shows 0. I even put > > > this is my view: > > > > <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> > > > > And it also always shows 0. What am I doing wrong? > > > I''d check the development.log file to see what parameters are actually > > getting submitted. > > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
<p> <%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %> </p> <p> <%= @sum %> </p> That''s all of it. My controller: class UserController < ApplicationController def home a = params[:number_one].to_i b = params[:number_one].to_i @sum = a + b end end On Oct 26, 5:40 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 26 Oct, 20:56, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It doesn''t say any numbers, the relevant log info just says it > > processed the GET and got the layout. > > Sounds like the parameters aren''t getting sent > What does the rest of the view with the form look like? > > Fred > > > On Oct 26, 4:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > > > > On Oct 26, 3:18 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Ok, so I figured out what was causing the error, I wasnt calling > > > > params[:number_one] in the right place. Fixing this took care of the > > > > error. Now I can call them in my controller like so: > > > > > @a = params[:number_one].to_i > > > > @b = params[:number_one].to_i > > > > @sum = @a + @b > > > > > But when I put numbers in my text boxes, it always shows 0. I even put > > > > this is my view: > > > > > <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> > > > > > And it also always shows 0. What am I doing wrong? > > > > I''d check the development.log file to see what parameters are actually > > > getting submitted. > > > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 26, 10:48 pm, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> <p> > <%= text_field_tag(:number_one, value = 0) %> > <%= text_field_tag(:number_two, value = 0) %> > </p> > <p> > <%= @sum %> > </p> > > That''s all of it.Time for HTML lesson 1: if you want inputs to get sent to the server, they need to be enclosed in a form (modulo javascript trickery). Fred> > My controller: > > class UserController < ApplicationController > def home > a = params[:number_one].to_i > b = params[:number_one].to_i > @sum = a + b > end > end > > On Oct 26, 5:40 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > On 26 Oct, 20:56, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It doesn''t say any numbers, the relevant log info just says it > > > processed the GET and got the layout. > > > Sounds like the parameters aren''t getting sent > > What does the rest of the view with the form look like? > > > Fred > > > > On Oct 26, 4:32 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > > > > On Oct 26, 3:18 am, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Ok, so I figured out what was causing the error, I wasnt calling > > > > > params[:number_one] in the right place. Fixing this took care of the > > > > > error. Now I can call them in my controller like so: > > > > > > @a = params[:number_one].to_i > > > > > @b = params[:number_one].to_i > > > > > @sum = @a + @b > > > > > > But when I put numbers in my text boxes, it always shows 0. I even put > > > > > this is my view: > > > > > > <p><%= params[:number_one].to_i + params[:number_two].to_i %></p> > > > > > > And it also always shows 0. What am I doing wrong? > > > > > I''d check the development.log file to see what parameters are actually > > > > getting submitted. > > > > > Fred-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #957392:> On Oct 26, 10:48pm, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> <p> >> <%= text_field_tag(:number_one, value = 0) %> >> <%= text_field_tag(:number_two, value = 0) %> >> </p> >> <p> >> <%= @sum %> >> </p> >> >> That''s all of it. > > Time for HTML lesson 1: if you want inputs to get sent to the server, > they need to be enclosed in a form (modulo javascript trickery). > > FredExactly. So you may want to change the view code to look like this: <%= form_tag(''/'') do -%> <p> <%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %> <%= submit_tag ''Calculate'' %> </p> <% end %> <p> <%= @sum %> </p> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you guys so much for your help. I think I have everything working now. It must be frustrating dealing with such simple issues. Just one more question: Did you intend to put the " - " in <%form_tag(''/'') do -%> ? I removed it and it didn''t seem to change anything. Thanks again for the help. On Oct 27, 1:30 am, "Eric R." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #957392: > > > On Oct 26, 10:48pm, debalmoto <debalm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> <p> > >> <%= text_field_tag(:number_one, value = 0) %> > >> <%= text_field_tag(:number_two, value = 0) %> > >> </p> > >> <p> > >> <%= @sum %> > >> </p> > > >> That''s all of it. > > > Time for HTML lesson 1: if you want inputs to get sent to the server, > > they need to be enclosed in a form (modulo javascript trickery). > > > Fred > > Exactly. > > So you may want to change the view code to look like this: > > <%= form_tag(''/'') do -%> > <p> > <%= text_field_tag(:number_one, value = 0) %> > <%= text_field_tag(:number_two, value = 0) %> > <%= submit_tag ''Calculate'' %> > </p> > <% end %> > <p> > <%= @sum %> > </p> > > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.