Loganathan Sellapa
2012-Aug-14 06:50 UTC
How to define virtual attribute for date_select drop menu using active model
Hi All, I am using active model for payment process in my application , i am not able to add field for date field, since it throws error as below *undefined method `card_expiration_date(3i)=''*. *In model: * include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming* * attr_accessor: card_expiration_date *In view:* <%=f.date_select :card_expiration_date, :add_month_numbers => false,:discard_day => true, :start_year => (Date.today.year-10), :end_year => (Date.today.year+10),:order=>[ :month,:year] %> Any help would be appreciated. regards, Loganathan ViewMe <http://vizualize.me/loganathan> -- 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-Aug-14 07:36 UTC
Re: How to define virtual attribute for date_select drop menu using active model
On 14 August 2012 07:50, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi All, > > I am using active model for payment process in my application , i am not > able to add field for date field, since it throws error as below undefined > method `card_expiration_date(3i)=''. > > In model: > include ActiveModel::Validations > include ActiveModel::Conversion > extend ActiveModel::Naming > > attr_accessor: card_expiration_dateWhat is the purpose of the line above? Check the docs for attr_accessor to see what it does. Colin> > In view: > > <%=f.date_select :card_expiration_date, :add_month_numbers => > false,:discard_day => true, :start_year => (Date.today.year-10), :end_year > => (Date.today.year+10),:order=>[ :month,:year] %> >-- 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.
Loganathan Sellapa
2012-Aug-14 07:44 UTC
Re: How to define virtual attribute for date_select drop menu using active model
I thought it would create getter and setter methods for "card_expiration_date" and the active model library would do the rest(such as creating virtual attributes card_expiration_date(1i), card_expiration_date(2li),card_expiration_date(3li) for date time attribute( card_expiration_date), let me know if I am wrong. regards, Loganathan ViewMe <http://vizualize.me/loganathan> On Tue, Aug 14, 2012 at 1:06 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 14 August 2012 07:50, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Hi All, > > > > I am using active model for payment process in my application , i am not > > able to add field for date field, since it throws error as below > undefined > > method `card_expiration_date(3i)=''. > > > > In model: > > include ActiveModel::Validations > > include ActiveModel::Conversion > > extend ActiveModel::Naming > > > > attr_accessor: card_expiration_date > > What is the purpose of the line above? Check the docs for > attr_accessor to see what it does. > > Colin > > > > > In view: > > > > <%=f.date_select :card_expiration_date, :add_month_numbers => > > false,:discard_day => true, :start_year => (Date.today.year-10), > :end_year > > => (Date.today.year+10),:order=>[ :month,:year] %> > > > > -- > 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.
Colin Law
2012-Aug-14 08:00 UTC
Re: How to define virtual attribute for date_select drop menu using active model
On 14 August 2012 08:44, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I thought it would create getter and setter methods for > "card_expiration_date" and the active model library would do the rest(such > as creating virtual attributes > card_expiration_date(1i),card_expiration_date(2li),card_expiration_date(3li) > for date time attribute(card_expiration_date), let me know if I am wrong.Please don''t top post, it makes it difficult to follow the thread. Insert your reply inline in the previous message. Thanks. You don''t need to specify att_accessor for fields in the database, ActiveRecord will supply them automatically. By providing them yourself you have disabled the automatic ones. I guess you are a beginner with Rails so I suggest that you work through some tutorials to understand the basics. railstutorial.org is good and is free to use online. Colin> > regards, > Loganathan > ViewMe > > > > > > On Tue, Aug 14, 2012 at 1:06 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 14 August 2012 07:50, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> > Hi All, >> > >> > I am using active model for payment process in my application , i am not >> > able to add field for date field, since it throws error as below >> > undefined >> > method `card_expiration_date(3i)=''. >> > >> > In model: >> > include ActiveModel::Validations >> > include ActiveModel::Conversion >> > extend ActiveModel::Naming >> > >> > attr_accessor: card_expiration_date >> >> What is the purpose of the line above? Check the docs for >> attr_accessor to see what it does. >> >> Colin >> >> > >> > In view: >> > >> > <%=f.date_select :card_expiration_date, :add_month_numbers => >> > false,:discard_day => true, :start_year => (Date.today.year-10), >> > :end_year >> > => (Date.today.year+10),:order=>[ :month,:year] %> >> > >> >> -- >> 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. > >-- 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.
Loganathan Sellapa
2012-Aug-14 08:40 UTC
Re: How to define virtual attribute for date_select drop menu using active model
My model* doesn''t use Activerecord* ORM, I need to do validation on the table less model, so I am using the Activemodel library, also I hope the virtual field are needs to be mentioned as "attr_accessor" and I am sorry to mention that the model is table less in previous mail, since I thought people will understand when I say Activemodel. regards, Loganathan ViewMe <http://vizualize.me/loganathan> On Tue, Aug 14, 2012 at 1:30 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 14 August 2012 08:44, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > I thought it would create getter and setter methods for > > "card_expiration_date" and the active model library would do the > rest(such > > as creating virtual attributes > > > card_expiration_date(1i),card_expiration_date(2li),card_expiration_date(3li) > > for date time attribute(card_expiration_date), let me know if I am wrong. > > Please don''t top post, it makes it difficult to follow the thread. > Insert your reply inline in the previous message. Thanks. > > You don''t need to specify att_accessor for fields in the database, > ActiveRecord will supply them automatically. By providing them > yourself you have disabled the automatic ones. > > I guess you are a beginner with Rails so I suggest that you work > through some tutorials to understand the basics. railstutorial.org is > good and is free to use online. > > Colin > > > > > regards, > > Loganathan > > ViewMe > > > > > > > > > > > > On Tue, Aug 14, 2012 at 1:06 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> > wrote: > >> > >> On 14 August 2012 07:50, Loganathan Sellapa <loganathan.ms-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> wrote: > >> > Hi All, > >> > > >> > I am using active model for payment process in my application , i am > not > >> > able to add field for date field, since it throws error as below > >> > undefined > >> > method `card_expiration_date(3i)=''. > >> > > >> > In model: > >> > include ActiveModel::Validations > >> > include ActiveModel::Conversion > >> > extend ActiveModel::Naming > >> > > >> > attr_accessor: card_expiration_date > >> > >> What is the purpose of the line above? Check the docs for > >> attr_accessor to see what it does. > >> > >> Colin > >> > >> > > >> > In view: > >> > > >> > <%=f.date_select :card_expiration_date, :add_month_numbers => > >> > false,:discard_day => true, :start_year => (Date.today.year-10), > >> > :end_year > >> > => (Date.today.year+10),:order=>[ :month,:year] %> > >> > > >> > >> -- > >> 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. > > > > > > -- > 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.
pepe
2012-Aug-15 13:48 UTC
Re: How to define virtual attribute for date_select drop menu using active model
I have never done this. Just trying to help. I think the problem you''re having is that your field doesn''t have a date compatible value. If you check it''s class it might be NilClass. Since the fields does not belong to a table date_select probably has no idea what to do with it because it doesn''t have a ''type''. Have you tried to give the field a Date compatible value before your view is executed, just to try if the view works? Also, maybe type_cast (in ActiveRecord::ConnectionAdapters::Quoting: http://api.rubyonrails.org/ ) would help? On Tuesday, August 14, 2012 4:40:52 AM UTC-4, Loganathan Sellappa wrote:> > My model* doesn''t use Activerecord* ORM, I need to do validation on the > table less model, so I am using the Activemodel library, also I hope the > virtual field are needs to be mentioned as "attr_accessor" and I am sorry > to mention that the model is table less in previous mail, since I thought > people will understand when I say Activemodel. > > regards, > Loganathan > ViewMe <http://vizualize.me/loganathan> > > > On Tue, Aug 14, 2012 at 1:30 PM, Colin Law <cla...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org<javascript:> > > wrote: > >> On 14 August 2012 08:44, Loganathan Sellapa <logana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:>> >> wrote: >> > I thought it would create getter and setter methods for >> > "card_expiration_date" and the active model library would do the >> rest(such >> > as creating virtual attributes >> > >> card_expiration_date(1i),card_expiration_date(2li),card_expiration_date(3li) >> > for date time attribute(card_expiration_date), let me know if I am >> wrong. >> >> Please don''t top post, it makes it difficult to follow the thread. >> Insert your reply inline in the previous message. Thanks. >> >> You don''t need to specify att_accessor for fields in the database, >> ActiveRecord will supply them automatically. By providing them >> yourself you have disabled the automatic ones. >> >> I guess you are a beginner with Rails so I suggest that you work >> through some tutorials to understand the basics. railstutorial.org is >> good and is free to use online. >> >> Colin >> >> > >> > regards, >> > Loganathan >> > ViewMe >> > >> > >> > >> > >> > >> > On Tue, Aug 14, 2012 at 1:06 PM, Colin Law <cla...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org<javascript:>> >> wrote: >> >> >> >> On 14 August 2012 07:50, Loganathan Sellapa <logana...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org<javascript:> >> > >> >> wrote: >> >> > Hi All, >> >> > >> >> > I am using active model for payment process in my application , i am >> not >> >> > able to add field for date field, since it throws error as below >> >> > undefined >> >> > method `card_expiration_date(3i)=''. >> >> > >> >> > In model: >> >> > include ActiveModel::Validations >> >> > include ActiveModel::Conversion >> >> > extend ActiveModel::Naming >> >> > >> >> > attr_accessor: card_expiration_date >> >> >> >> What is the purpose of the line above? Check the docs for >> >> attr_accessor to see what it does. >> >> >> >> Colin >> >> >> >> > >> >> > In view: >> >> > >> >> > <%=f.date_select :card_expiration_date, :add_month_numbers => >> >> > false,:discard_day => true, :start_year => (Date.today.year-10), >> >> > :end_year >> >> > => (Date.today.year+10),:order=>[ :month,:year] %> >> >> > >> >> >> >> -- >> >> 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 rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> >> To unsubscribe from this group, send email to >> >> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> >> 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 rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> > To unsubscribe from this group, send email to >> > rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> > 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 rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To unsubscribe from this group, send email to >> rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/EL0Qv8uCIVkJ. For more options, visit https://groups.google.com/groups/opt_out.