OK, so I''m an absolute noob at Ruby on Rails. I''ve read a lot of information I can find about form_for and most of them use form_for to create new items that get saved into the database and can be viewed later to edit, destroy, etc. In this case, the database will fill up with whatever the user wrote and I just want my program to have no information stored. I''ve been trying to take a user''s input from the text_field or file_field and once they hit the "submit" button, they get redirected to another page that, for instance, says "You wrote: [insert user input here]" I''ve been having no luck whatsoever doing this except to use HTML form, but I was hoping I can do this in Ruby on Rails. Thanks for any help, anon_comp -- 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 26 May 2010 19:06, anon_comp <neocoolstar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> OK, so I''m an absolute noob at Ruby on Rails. I''ve read a lot of > information I can find about form_for and most of them use form_for to > create new items that get saved into the database and can be viewed > later to edit, destroy, etc. In this case, the database will fill up > with whatever the user wrote and I just want my program to have no > information stored. > > I''ve been trying to take a user''s input from the text_field or > file_field and once they hit the "submit" button, they get redirected > to another page that, for instance, says "You wrote: [insert user > input here]" I''ve been having no luck whatsoever doing this except to > use HTML form, but I was hoping I can do this in Ruby on Rails.If the form is not associated with a model then form_tag may be more appropriate. Colin -- 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 May 26, 2:41 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> If the form is not associated with a model then form_tag may be more > appropriate.Going by your suggestion, Colin, my project looks like this trying_controller.rb: class TryingController < ApplicationController def index end def to @name = params[:title] end end index.html.erb: <% form_tag :action => :to %> <label for="name">Name:</label> <%= text_field_tag :name, params[:name] %> <%= submit_tag "OK" %> </form> to.html.erb: Name: <%= @name %> The submit button doesn''t work... -- 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 May 2010 20:04, anon_comp <neocoolstar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 26, 2:41 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> If the form is not associated with a model then form_tag may be more >> appropriate. > > Going by your suggestion, Colin, my project looks like this > > trying_controller.rb: > class TryingController < ApplicationController > def index > end > > def to > @name = params[:title] > end > end > > index.html.erb: > <% form_tag :action => :to %> > <label for="name">Name:</label> > <%= text_field_tag :name, params[:name] %> > <%= submit_tag "OK" %> > </form> > > to.html.erb: > Name: <%= @name %> > > The submit button doesn''t work...In what way does it not work? Did you check the html to see if it is what you expect? I think it should be :action = ''to'' rather than :to Also when things are not working as you expect the log file (log/development.log) can often be useful in analysing the problem. Colin -- 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 May 2010 22:01, anon_comp <neocoolstar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 26, 4:30 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> In what way does it not work? > > When I hit the "OK" button nothing happens, it stays on the same page. > >> Did you check the html to see if it is what you expect? > > I ran the server and looked at the page if that''s what you mean, yes.I meant that you should check that the html for the form is correct html for a form with a submit button. I think you may find that there is a </form> where you do not expect it, (separate from the one you have manually added). Looking at your code you have got the use of form_tag wrong. Unfortunately you have snipped your original code so it is difficult to insert the corrections. Have another look at the docs for form_tag, you will see there should be a ''do'' there and there is no need to add the </form> yourself.> >> I think it should be :action = ''to'' rather than :to > > It didn''t affect anything, I beleive they mean the same thing.They don''t mean the same thing, though sometimes they are interchangeable. I am not sure in this case, again check the html to see if it is correct. Colin> >> Also when things are not working as you expect the log file >> (log/development.log) can often be useful in analysing the problem. > > Thanks for the tip. It processed the index page but nothing registered > when I hit the OK button. > > I really appreciate your replies. > > anon_comp-- 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 May 2010 22:15, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 May 2010 22:01, anon_comp <neocoolstar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On May 26, 4:30 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >>> In what way does it not work? >> >> When I hit the "OK" button nothing happens, it stays on the same page. >> >>> Did you check the html to see if it is what you expect? >> >> I ran the server and looked at the page if that''s what you mean, yes. > > I meant that you should check that the html for the form is correct > html for a form with a submit button. I think you may find that there > is a </form> where you do not expect it, (separate from the one you > have manually added).Use View, Page Source, or similar, in your browser to view the html. Colin> > Looking at your code you have got the use of form_tag wrong. > Unfortunately you have snipped your original code so it is difficult > to insert the corrections. Have another look at the docs for > form_tag, you will see there should be a ''do'' there and there is no > need to add the </form> yourself. > >> >>> I think it should be :action = ''to'' rather than :to >> >> It didn''t affect anything, I beleive they mean the same thing. > > They don''t mean the same thing, though sometimes they are > interchangeable. I am not sure in this case, again check the html to > see if it is correct. > > Colin > >> >>> Also when things are not working as you expect the log file >>> (log/development.log) can often be useful in analysing the problem. >> >> Thanks for the tip. It processed the index page but nothing registered >> when I hit the OK button. >> >> I really appreciate your replies. >> >> anon_comp >-- 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.
Problem solved. Thank you very much Colin for the excellent help :) I just had to change the def to in my controller class TryingController < ApplicationController def index end def to @name = params[:name] end end -- 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.