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.
on 2012-12-15 05:24
on 2012-12-15 06:34
On Sat, Dec 15, 2012 at 12:24 PM, Mas Bejo <lists@ruby-forum.com> 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 :) > <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 http://api.rubyonrails.org/classes/ActiveRecord/Ca... > For more options, visit https://groups.google.com/groups/opt_out. > > > --
on 2012-12-15 13:34
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.
<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
on 2012-12-15 14:21
On Sat, Dec 15, 2012 at 8:34 PM, Mas Bejo <lists@ruby-forum.com> 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. > <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? > For more options, visit https://groups.google.com/groups/opt_out. > > > --
on 2012-12-15 14:28
On 15 December 2012 12:34, Mas Bejo <lists@ruby-forum.com> 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. > <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
on 2012-12-15 14:36
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
<div class="field">
<%= f.label :ttl %></td><td>
<%= f.label :":" %></td><td>
<%= f.text_field :tempat %>
<tr>
<td colspan="3" align="right">
<%= select_date :tanggal %></td></tr>
</div>
but it make this error
{:as=>:TTL} is not a symbol
can you help me?
on 2012-12-15 15:55
On Dec 15, 2012, at 8:36 AM, Mas Bejo 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
on 2012-12-15 16:19
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
on 2012-12-16 07:56
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...
on 2012-12-16 09:24
On 16 December 2012 06:56, Mas Bejo <lists@ruby-forum.com> 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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.