Select and how to read the api

I’m trying to understand how to use the select, especially how to make
an option selected. I want to add the values manually, but be sure one
value is selected when finding an existing post in the db.

How are you supposed to understand how to do that from this?

This is what I’ve used until now:

<%= select ‘user’, ‘age’,
[’’,‘10-20’,‘20-30’,‘30-40’,‘40-50’,‘50-60’,‘60-70’,‘70+’] %>

Pål Bergström wrote:

I’m trying to understand how to use the select, especially how to make
an option selected. I want to add the values manually, but be sure one
value is selected when finding an existing post in the db.

How are you supposed to understand how to do that from this?

http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000940

This is what I’ve used until now:

<%= select ‘user’, ‘age’,
[’’,‘10-20’,‘20-30’,‘30-40’,‘40-50’,‘50-60’,‘60-70’,‘70+’] %>

Got it.

<%= select ‘user’, ‘age’,
[’’,‘10-20’,‘20-30’,‘30-40’,‘40-50’,‘50-60’,‘60-70’,‘70+’], :selected =>
@selected_value %>

Is that described in the api? I can’t find it.

<%= select ‘user’, ‘age’,
[’’,‘10-20’,‘20-30’,‘30-40’,‘40-50’,‘50-60’,‘60-70’,‘70+’], :selected =>
@selected_value %>

Is that described in the api? I can’t find it.

Try select_tag

(And note to whoever named a method ‘select’ - please don’t!!!)

Try select_tag

(And note to whoever named a method ‘select’ - please don’t!!!)

Does it say how to make a value selected? Can you add values manually
like my example, without adding the actual option-tag? If not I don’t
understand the point of using a ror select method instead of a regular
html select.

Why not use ‘select’? It works fine.

(And note to whoever named a method ‘select’ - please don’t!!!)

Why not use ‘select’? It works fine.

Because programs must share a large namespace in memory, and a larger
one in
our brains. ‘select’ is already used by Array, certain network sockets,
and
(in some languages) a keyword. Primitive things should have primeval
names,
such as ‘select’, and complex & specific things should have decorated
names.
If all the other Rails HTML generators end in tag, then select should
too!

Phlip wrote:

(And note to whoever named a method ‘select’ - please don’t!!!)

Why not use ‘select’? It works fine.

Because programs must share a large namespace in memory, and a larger
one in
our brains. ‘select’ is already used by Array, certain network sockets,
and
(in some languages) a keyword. Primitive things should have primeval
names,
such as ‘select’, and complex & specific things should have decorated
names.
If all the other Rails HTML generators end in tag, then select should
too!

I understand. But it must be a Rails-tag, otherwise it wouldn’t work.

I just couldn’t get the select_tag to work with manual values. I mean
what’s the point of using it, and some other rails-tags actually, when
it’s as much hassle to write the html-tag?

I think this is a good example of the backside of Rails, the
documentation. I wonder if they plan to update it? Wouldn’t hurt if they
did.

This is the last sentence in the link you posted:
“Specify :selected => value to use a different selection or :selected
=> nil to leave all options unselected.”

On May 17, 7:43 am, Pål Bergström [email protected]

Actually a rails documentation project has been around for a while now.
In fact, not only is it around but its open to whoever wants to help
improve the documentation. Anyone can get commit rights so you can make
changes and add them directly into this which will then be merged back
into rails.

In fact, I strongly encourage you to take this into your own hands. Is
there a part of rails that is poorly documented?

http://github.com/lifo/docrails/tree/master

You can make it right.

On 17 May 2008, at 21:03, Phlip wrote:

names,
such as ‘select’, and complex & specific things should have
decorated names.
If all the other Rails HTML generators end in tag, then select
should too!

There is a select_tag helper, which is different. In the same way that
the raw check_box_tag, text_field_tag have equivalents without the
_tag that operate on a controller instance variable, select_tag’s
equivalent is plain old select. select can mean a bunch of different
things but then again we frequently overload operators, so why not
method names too ?

Fred

Frederick C. wrote:

On 17 May 2008, at 21:03, Phlip wrote:

There is a select_tag helper, which is different. In the same way that
the raw check_box_tag, text_field_tag have equivalents without the
_tag that operate on a controller instance variable, select_tag’s
equivalent is plain old select. select can mean a bunch of different
things but then again we frequently overload operators, so why not
method names too ?

Fred

True. Thanks for the clarification.

Nathan E. wrote:

Actually a rails documentation project has been around for a while now.
In fact, not only is it around but its open to whoever wants to help
improve the documentation. Anyone can get commit rights so you can make
changes and add them directly into this which will then be merged back
into rails.

In fact, I strongly encourage you to take this into your own hands. Is
there a part of rails that is poorly documented?

http://github.com/lifo/docrails/tree/master

You can make it right.

Good to know. Not a git user though. Maybe this will pull me into
version control. I haven’t found it valuable yet. I’ll take a look.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs