Forum: Ruby on Rails how to get information stored in a form by using ruby-rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 sayoyo (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi,

I'm a newbie with ruby-rails (also with web
developpement) I want to create a form to get data
from the user, like text field and combobax, button,
etc. I used "text_field_tag" or other "tag" to
genenate those components on the html, but after that
I have no idea how to get the data from the
components, I read the examples and documentations
about how to create the componenets, but I didn't find
anything which talk about how to extract them... Can
someone please tell me how to do it or where can I
find the documentation!!!

Thanks you very much!!!!

sayoyo





__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 duane.johnson (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On Nov 9, 2005, at 7:55 AM, Saiho Yuen wrote:

> anything which talk about how to extract them... Can
> someone please tell me how to do it or where can I
> find the documentation!!!

Is there any particular reason you're using 'tag' and
'text_field_tag'?  It's usually much simpler to use the form
helpers.  For example, in a view such as edit.rhtml:

<%= text_field 'user', 'name' %>

and then in your controller you could access the user's name via:

def edit
   @name = params[:user][:name]
end

If you need further help, perhaps you can be more specific with your
question or show examples of what you've already tried and why.

Duane Johnson
(canadaduane)
14b7344777a56ac9a1fad849f5d6da2a?d=identicon&s=25 sayoyo (Guest)
on 2005-11-12 12:49
(Received via mailing list)
Hi,

the reason I use "_tag" is because I don't have a
model (no database) If I understand well the mecanism,
the helpers without "tag", they send information
directly to the model...so that's why I didn't used
them.

After a lot of tryings, I find out that I can get the
info from the variable "@params", like
"@params['post'], but I don't know if it is the
correct way to get the information.

Thanks you very much

sayoyo

this is an example.

def buildTable
   if @params.include?('post') then
      @checkTextField = @params['post']
   else
      @checkTextField = nil
   end
end

buildTable.rhtml
<html>
	<head>
		<title>Build Table</title>
	</head>
	<body>
	<%= start_form_tag :action => :buildTable %> <br>

	<%= text_field_tag(name = "post", nil, "size" =>
"20", "maxsize"=>"20") %> <br>

	<%= submit_tag(value = "run") %>
	<%= submit_tag(value = "cancel") %><br>
	<%= end_form_tag %>

	<%= @checkTextField %>
	<%= debug(@params) %>
	</body>
</html>




--- Duane Johnson <duane.johnson@gmail.com> wrote:

> > genenate those components on the html, but after
> Is there any particular reason you're using 'tag'
> def edit
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>




__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 duane.johnson (Guest)
on 2005-11-12 12:49
(Received via mailing list)
On Nov 9, 2005, at 1:39 PM, Saiho Yuen wrote:

> "@params['post'], but I don't know if it is the
> correct way to get the information.
>
> Thanks you very much
>
No problem.  Some comments about the code below...

> def buildTable
>    if @params.include?('post') then
>       @checkTextField = @params['post']
>    else
>       @checkTextField = nil
>    end
> end

This method could be simplified, like this:
def buildTable
   @checkTextField = params[:post]
end

If there is no 'post' key in the params hash, then it will be nil by
default so there's no need to add the conditional statement.

>
> buildTable.rhtml
> <html>
> 	<head>
> 		<title>Build Table</title>
> 	</head>
> 	<body>
> 	<%= start_form_tag :action => :buildTable %> <br>
>
You may consider using the convention of underscores instead of
camelCase, e.g.: start_form_tag :action => build_table.  It's a Ruby
convention that Rails sometimes relies on for conversion between
camelCase and underscored variables.

> 	<%= text_field_tag(name = "post", nil, "size" =>
> "20", "maxsize"=>"20") %> <br>
>
> 	<%= submit_tag(value = "run") %>
> 	<%= submit_tag(value = "cancel") %><br>

The above two lines look a little odd to me... you're assigning the
variable called 'value' twice, but then not using it below.  Perhaps
you meant to use a symbol-as-key hash like this:

submit_tag(:value => "run")
submit_tag(:value => "cancel")

Good luck!
Duane Johnson
(canadaduane)
This topic is locked and can not be replied to.