Mas Bejo
2012-Dec-15 04:24 UTC
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. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-15 05:32 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
On Sat, Dec 15, 2012 at 12:24 PM, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 :)> > > 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 http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Mas Bejo
2012-Dec-15 12:34 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Jim Ruther Nill
2012-Dec-15 13:19 UTC
Re: Re: Combo Box in rails and save 2 value in diffrent field in one field at database
On Sat, Dec 15, 2012 at 8:34 PM, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 tryrails 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?> > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Dec-15 13:27 UTC
Re: Re: Combo Box in rails and save 2 value in diffrent field in one field at database
On 15 December 2012 12:34, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 valueFirst 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 databaseIt is really better to only have one question at a time, otherwise the answers will get confusing. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Mas Bejo
2012-Dec-15 13:36 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
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? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2012-Dec-15 14:54 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
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> > ------------------------------------------------- > 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? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Mas Bejo
2012-Dec-15 15:19 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Mas Bejo
2012-Dec-16 06:56 UTC
Re: Combo Box in rails and save 2 value in diffrent field in one field at database
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... -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Dec-16 08:22 UTC
Re: Re: Combo Box in rails and save 2 value in diffrent field in one field at database
On 16 December 2012 06:56, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.