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,

<%= f.label :ttl %> <%= f.label :":" %> <%= f.text_field :TTL %> <%= select_date %>

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.

On Sat, Dec 15, 2012 at 12:24 PM, Mas B. [email protected] wrote:

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:

<tr>
<%= select_date %>

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 http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html

For more options, visit https://groups.google.com/groups/opt_out.

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


and for second problem, i get this syntax.

<%= f.label :ttl %> <%= f.label :":" %> <%= f.text_field :TTL %> <%= select_date %>

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

On Sat, Dec 15, 2012 at 8:34 PM, Mas B. [email protected] wrote:

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.

<%= select_date %>

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?

For more options, visit https://groups.google.com/groups/opt_out.

On 15 December 2012 12:34, Mas B. [email protected] wrote:

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.

<%= select_date %>

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

On Dec 15, 2012, at 8:36 AM, Mas B. wrote:

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

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.


for second problem i change my model file to be like this:

class Anggotum < ActiveRecord::Base
set_table_name “anggota”
attr_accessible :NP, :Nama, :Alamat, :TTL, :Telp, :Email, :Password,
:Waktu_Daftar, :Posisi, :Jenis_Kelamin
attr_accessor :tempat, :tanggal, :as=> :TTL
end

and in my form.html.rb that connect to new.html.rb i add this syntax

<%= f.label :ttl %> <%= f.label :":" %> <%= f.text_field :tempat %> <%= select_date :tanggal %>

but it make this error
{:as=>:TTL} is not a symbol

can you help me?

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…

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

i want to make like this

<%= f.label :status %> <%= f.label :":" %> <%= f.text_field :Status %>

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

On 16 December 2012 06:56, Mas B. [email protected] wrote:

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

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