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, 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.
Jordon Bedwell
2012-Dec-16 04:07 UTC
Re: save 2 value in diffrent field in one field at database
On Sat, Dec 15, 2012 at 9:53 PM, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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, > i change my model file to be like this:See: http://api.rubyonrails.org/classes/ActiveRecord/Base.html (search "serialize") ...If you want to be able to be able to select by that field you''ll need a custom serializer and PostgreSQL so you can use Hstore (you can also use JSON datatype in PostgreSQL 9.2 but that requires even more work because JSON is still a new feature so it doesn''t have the same select support that Hstore has.) -- 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 05:11 UTC
Re: save 2 value in diffrent field in one field at database
so, did you mean. i must 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 serialize :TTL #{'':TTL''} << #{'':tempat''] + #{'':tanggal''} end it true? -- 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:31 UTC
Re: save 2 value in diffrent field in one field at database
i edit 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 serialize :TTL string "tempat" date "tanggal" #{'':TTL''} << #{''tempat''] + #{''tanggal''} end and change the field in _form.html.rb file to be like this: .... <div class="field"> <%= f.label :ttl %></td><td> <%= f.label :":" %></td><td> <%= f.text_field ''tempat'' %> <tr> <td colspan="3" align="right"> <%= date_select ''tanggal'', ''tanggal'', {:start_year => 1950, :order => [:month, :day, :year]} %> </div> ........ rails say this error "NoMethodError in AnggotaController#index undefined method `key?'' for nil:NilClass" -- 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:20 UTC
Re: Re: save 2 value in diffrent field in one field at database
On 16 December 2012 06:31, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> i edit 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 > serialize :TTL > string "tempat" > date "tanggal" > #{'':TTL''} << #{''tempat''] + #{''tanggal''} > end > > and change the field in _form.html.rb file to be like this: > .... > <div class="field"> > <%= f.label :ttl %></td><td> > <%= f.label :":" %></td><td> > <%= f.text_field ''tempat'' %> > <tr> > <td colspan="3" align="right"> > <%= date_select ''tanggal'', ''tanggal'', {:start_year => 1950, :order > => [:month, :day, :year]} %> > </div> > ........ > > rails say this error > > "NoMethodError in AnggotaController#index > > undefined method `key?'' for nil:NilClass"Have a good look at the Rails Guide on Debugging. It will show you how to debug your code. Also I suggest that you work right through a good tutorial on Rails, such as railstutorial.org, which is free to use online. Then you will get a better understanding of how Rails works. 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.
Jim Ruther Nill
2012-Dec-16 10:27 UTC
Re: save 2 value in diffrent field in one field at database
Sent from my iPhone On 16/12/2012, at 11:53 AM, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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, > 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?I told you to read on virtual attributes and callbacks. To give you a clue on what you need to do, you need to create 2 virtual atteibutes: one for the text field and one for the date select. Then use a before validation callback to concatenate them. Or just as colin suggested, concatenate them in the controller but i''d like to so these things in the model.> > -- > 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@googlegroups.com. > 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@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Colin Law
2012-Dec-16 10:58 UTC
Re: save 2 value in diffrent field in one field at database
On 16 December 2012 10:27, Jim Ruther Nill <jvnill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 16/12/2012, at 11:53 AM, Mas Bejo <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> 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, >> 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? > > I told you to read on virtual attributes and callbacks. To give you a clue on what you need to do, you need to create 2 virtual atteibutes: one for the text field and one for the date select. Then use a before validation callback to concatenate them. Or just as colin suggested, concatenate them in the controller but i''d like to so these things in the model.You are right of course Jim, I was just trying to make it easier for the guy to understand, but yes, Mas Bejo it is better to put such code in the model. 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@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.