Dag Stensson
2008-Apr-03 09:15 UTC
set a default value to a "text/blob" field at creation?
Is it possible somehow to incorporate "this is a text" into a "blob/text"-value in the database when the row is created? It''s not possible to do with a default value hence it''s a "blob/text"-value. At the moment I create the row for a user with: @presentation = current_user.presentation @presentation = current_user.create_presentation unless @presentation -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dag Stensson
2008-Apr-03 12:40 UTC
Re: set a default value to a "text/blob" field at creation?
I tried to create this in my lib file string.rb to show something else if the value was nil...(and required the ''string.rb'' in my application helper) def or_empty(alternate) (self.nil? or self == "") ? alternate : self end but that didn''t work either. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Julian Leviston
2008-Apr-04 00:13 UTC
Re: set a default value to a "text/blob" field at creation?
You''d need to open the class up to do this. class String def or_empty(alternate = ''default'') self.blank? ? alternate : self end That would work. Julian. Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3 OUT APRIL 6 http://sensei.zenunit.com/ On 03/04/2008, at 11:40 PM, Dag Stensson wrote:> > I tried to create this in my lib file string.rb to show something else > if the value was nil...(and required the ''string.rb'' in my application > helper) > > def or_empty(alternate) > (self.nil? or self == "") ? alternate : self > end > > but that didn''t work either. > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dag Stensson
2008-Apr-04 09:08 UTC
Re: set a default value to a "text/blob" field at creation?
Julian Leviston wrote:> You''d need to open the class up to do this. > > class String > def or_empty(alternate = ''default'') > self.blank? ? alternate : self > end > > That would work. > > Julian. > > Learn Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) VIDEO #3 > OUT APRIL 6 > http://sensei.zenunit.com/Nope, that doesn''t do it, I still get an error "The error occurred while evaluating nil.or_empty" in this line of my show-view: <%= h @presentation.pres.or_empty("No presentation has been entered")%> because the there exists nothing in the pres-field. This is what I''m trying to fix. what do you mean with:> You''d need to open the class up to do this.-- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-04 09:21 UTC
Re: set a default value to a "text/blob" field at creation?
On 4 Apr 2008, at 10:08, Dag Stensson wrote:> > Nope, that doesn''t do it, > > I still get an error > "The error occurred while evaluating nil.or_empty" > > in this line of my show-view: > <%= h @presentation.pres.or_empty("No presentation has been entered") > %> > > because the there exists nothing in the pres-field. This is what I''m > trying to fix.How about you do this in your model def pres value_in_database = self[:pres] #do something with value_in_database end Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dag Stensson
2008-Apr-04 09:47 UTC
Re: set a default value to a "text/blob" field at creation?
Frederick Cheung wrote:> On 4 Apr 2008, at 10:08, Dag Stensson wrote: >> because the there exists nothing in the pres-field. This is what I''m >> trying to fix. > > How about you do this in your model > > def pres > value_in_database = self[:pres] > #do something with value_in_database > end > > FredI''m not quite sure I completely understand... =/ -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Apr-04 09:58 UTC
Re: set a default value to a "text/blob" field at creation?
On 4 Apr 2008, at 10:47, Dag Stensson wrote:> > Frederick Cheung wrote: >> On 4 Apr 2008, at 10:08, Dag Stensson wrote: >>> because the there exists nothing in the pres-field. This is what I''m >>> trying to fix. >> >> How about you do this in your model >> >> def pres >> value_in_database = self[:pres] >> #do something with value_in_database >> end >> >> Fred > > I''m not quite sure I completely understand... =/Overwrite the accessor that rails provides, using self[:pres] to get at the original value. Fred> > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dag Stensson
2008-Apr-04 11:19 UTC
Re: set a default value to a "text/blob" field at creation?
Frederick Cheung wrote:> On 4 Apr 2008, at 10:47, Dag Stensson wrote: > >>> #do something with value_in_database >>> end >>> >>> Fred >> >> I''m not quite sure I completely understand... =/ > > Overwrite the accessor that rails provides, using self[:pres] to get > at the original value. > > FredAlright, thanx a lot, solved the problem! -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---