Understanding the RoR API, noob questions here?

sorry for another post. id really like to understand the documentation
but this whole RoR stuff is nothing like c++. everything just magically
happens using ror.

my first question is this about the api…
//////////////////////////
select_tag(name, option_tags = nil, options = {})
Creates a dropdown selection box, or if the :multiple option is set to
true, a multiple choice selection box.
Helpers::FormOptions can be used to create common select boxes such as
countries, time zones, or associated records.
option_tags is a string containing the option tags for the select box:

Outputs <select id=“people”

name=“people”>David
select_tag “people”, “David”
Options:
:multiple - If set to true the selection will allow multiple choices.
//////////////////////

now i still dont understand what to substitue name, option_tags, options
= {}) for. are these also found in the documentation. in c++ we call
them arguments.
i tried this <%= select_tag(‘state’, option_tags = ‘NJ’, options = {})%>
in my form, but no drop down happens.

thanks for any help.

koloa wrote:

sorry for another post. id really like to understand the documentation
but this whole RoR stuff is nothing like c++. everything just magically
happens using ror.

my first question is this about the api…
//////////////////////////
select_tag(name, option_tags = nil, options = {})
Creates a dropdown selection box, or if the :multiple option is set to
true, a multiple choice selection box.
Helpers::FormOptions can be used to create common select boxes such as
countries, time zones, or associated records.
option_tags is a string containing the option tags for the select box:

Outputs <select id=“people”

name=“people”>David
select_tag “people”, “David”
Options:
:multiple - If set to true the selection will allow multiple choices.
//////////////////////

now i still dont understand what to substitue name, option_tags, options
= {}) for. are these also found in the documentation. in c++ we call
them arguments.
i tried this <%= select_tag(‘state’, option_tags = ‘NJ’, options = {})%>
in my form, but no drop down happens.

thanks for any help.

Hi Koloa,
Just in general, it looks like maybe you are trying to learn Rails
without looking at Ruby and HTML first. It can be done, but I think
that is the hard way to learn it.

The select_tag is a helper that builds some html for you based on what
you feed it. If you wrote the html yourself by looking in an html book,
it would be a “select tag” followed by several “option tags”. The
select tag helper just wants a string full of options like the
following…

<%= select_tag “wait_max”, “3 minutes
5 minutes
7 minutes
10 minutes
15 minutes”

In this case the string is being created “inline”. Another way is to
create the string first, such as by reading something from the database,
and then feed that array variable as the argument:
<% option_list = “” %>
<% for category in Question.categories %>
<% option_list << “#{category}” %>
<% end %>
<%= select_tag “category”, option_list -%>

The “options” argument is ironically optional.

best,
jp

Jeff P. wrote:

koloa wrote:

<%= select_tag “wait_max”, “3 minutes
5 minutes
7 minutes
10 minutes
15 minutes”

In this case the string is being created “inline”. Another way is to
create the string first, such as by reading something from the database,
and then feed that array variable as the argument:
<% option_list = “” %>
<% for category in Question.categories %>
<% option_list << “#{category}” %>
<% end %>
<%= select_tag “category”, option_list -%>

The “options” argument is ironically optional.

best,
jp

oops, noticed two mistakes already. First, I left off the closing %>
on the first example. Second, I should have said " and then feed that
‘string’ variable as the argument:" just before the second example.

jp

hi jeff, thanks for the awesome reply. i see now that the helper methods
help with creating html code. i guess in order to understand the ror
functions, do like you suggest, and also understand the html.

appreciate it, thanks!

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