Combo Box in rails and save 2 value in diffrent field in one field at database

i have problem to make combobox in rails can you help me. i try this syntax <%= f.select(:Status) %>

Status is my field in database that have 2 value "perempuan" and "laki-laki". but i always got error in my rails

and the second problem i want to get value from 2 diffrent field, first from text_field, and second from select_date, and i want to save it in one field "TTL" in database, this is the syntax,

<div class="field">     <%= f.label :ttl %></td><td>     <%= f.label :":" %></td><td>     <%= f.text_field :TTL %>     <tr>   <td colspan="3" align="right">     <%= select_date %></td></tr>   </div>

i confuse, how to get select_date value and concat it with value form text_field, and then save it in field "TTL" in database.

i have problem to make combobox in rails can you help me. i try this syntax <%= f.select(:Status) %>

Status is my field in database that have 2 value "perempuan" and "laki-laki". but i always got error in my rails

i don't understand your requirement for this one. so please clarify :slight_smile:

and the second problem i want to get value from 2 diffrent field, first from text_field, and second from select_date, and i want to save it in one field "TTL" in database, this is the syntax,

<div class="field">     <%= f.label :ttl %></td><td>     <%= f.label :":" %></td><td>     <%= f.text_field :TTL %>     <tr>   <td colspan="3" align="right">     <%= select_date %></td></tr>   </div>

i confuse, how to get select_date value and concat it with value form text_field, and then save it in field "TTL" in database.

you need to use virtual attributes and callbacks to achieve this. Read on attr_accessor and ActiveRecord::Callbacks

i get this syntax

    <%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki })%>

but, i didn't work, i just need to get value from that combobox, and send it to query insert to field "Status" in database, but when i try rails look it like null value

i get this syntax

    <%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki })%>

but, i didn't work, i just need to get value from that combobox, and send it to query insert to field "Status" in database, but when i try

rails look it like null value

Sorry Mas, I still don't get what you want.

----------------------------

and for second problem, i get this syntax.

<div class="field">     <%= f.label :ttl %></td><td>     <%= f.label :":" %></td><td>     <%= f.text_field :TTL %>     <tr>   <td colspan="3" align="right">     <%= select_date %></td></tr>   </div>

i want to concate value from "<%= f.text_field :TTL %>" and value from "<%= select_date %>" and send it to update field TTL in database

Have you read on callbacks and virtual attributes?

i get this syntax

    <%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki })%>

but, i didn't work, i just need to get value from that combobox, and send it to query insert to field "Status" in database, but when i try rails look it like null value

First you need to determine which area is going wrong. Firstly is the html that is being generated what you expect. Have a look at the html of the page (using View > Page Source or similar in your browser). Does that look ok? Secondly perhaps the data is not being sent to the server correctly. Look in log/development.log to check that the data is being passed and the correct action is being called. Thirdly perhaps there is an error in the action in the controller. Have a look at the Rails Guide on Debugging and it will show you techniques you can use to debug your code.

----------------------------

and for second problem, i get this syntax.

<div class="field">     <%= f.label :ttl %></td><td>     <%= f.label :":" %></td><td>     <%= f.text_field :TTL %>     <tr>   <td colspan="3" align="right">     <%= select_date %></td></tr>   </div>

i want to concate value from "<%= f.text_field :TTL %>" and value from "<%= select_date %>" and send it to update field TTL in database

It is really better to only have one question at a time, otherwise the answers will get confusing.

Colin

so, first i just need to get value from

"<%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki})%>"

because my field(field status) in database, i config as Set that have two value "Perempuan" ,and "Laki-Laki". but when i just write that syntax rails look value from "<%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki})%>" as null value.

so, first i just need to get value from

"<%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki})%>"

because my field(field status) in database, i config as Set that have two value "Perempuan" ,and "Laki-Laki". but when i just write that syntax rails look value from "<%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki})%>" as null value.

Did you type that last line, or copy and paste from your code?

:Status

or

:status

???

Ruby variables are usually snake-case. Classes are camel-case. Which is this?

Walter

this one :Status i copy it from my code (_form.html.rb file)

i want to make like this

<div class="field">     <%= f.label :status %></td><td>     <%= f.label :":" %></td><td>     <%= f.text_field :Status %>   </div>

but i didn't want make input from text_field, i want to input from select so i change     <%= f.text_field :Status %> to     <%=select_tag :Status, options_for_select(%w{ Perempuan Laki-Laki })%>

when i use text_field as input i got the value. but when i change it to select, rails say it nill value

i got the solution for my first problem.

but i haven't been got the solution for my second problem... how about to concate value form 2 field...

thanks for your help...

i got the solution for my first problem.

It is good practice to post the solution here so that others who find the thread by searching will see the solution to the problem.

but i haven't been got the solution for my second problem... how about to concate value form 2 field...

Just concatenate them in the controller, what is the problem?

Colin