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
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.
Julian L. 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.
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/
Frederick C. wrote:
On 4 Apr 2008, at 10:08, Dag S. 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… =/
On 4 Apr 2008, at 10:47, Dag S. 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.
Fred
On 4 Apr 2008, at 10:08, Dag S. 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
Frederick C. wrote:
On 4 Apr 2008, at 10:47, Dag S. 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.
Fred
Alright, thanx a lot, solved the problem!