I mean: Model.new().save

That book is pretty good, and the application interesting. Look at my 
version, it adds more tables, but in Datamapper

https://github.com/CharlyJazz/Frank-Sinatra/blob/master/models/models.rb


ps: you should create unit tests for your models and integration test for 
your sinatra routes.


El lunes, 16 de octubre de 2017, 23:09:59 (UTC-4), French Fry escribió:
>
> You mean you use create?  I just decided to forget about it after I came 
> across a post on here from 3 years back with a similar problem.  
>
> Yep, Jumpstart Sinatra. I really enjoyed it except it took me a bit longer 
> due to a) being relatively new to Ruby and very new to Sinatra plus I 
> decided to go with Sequel instead of Datamapper.  I wouldn't say 
> refactoring, just trying out some things before moving on. Darren did some 
> cool refactoring right within the book.  
>
> On Monday, October 16, 2017 at 8:48:18 PM UTC-6, Carlos Azuaje wrote:
>>
>> I always create a record I use new. And the save method by default has 
>> the argument: validate => true
>>
>> So it should work.
>>
>> Are you refactoring the application of the book Jump Start by Darren 
>> Jones? 
>>
>> El lunes, 16 de octubre de 2017, 20:43:25 (UTC-4), French Fry escribió:
>>>
>>> Got it figured out.  See even though I didn't have 
>>> #raise_error_on_save_failure set to false, using create was leaving my 
>>> object nil.  I don't know, maybe it needs to be set to true to not effect 
>>> the errors.  I just thought true was the default.  Now, that I am using new 
>>> and save, errors are working.  
>>>
>>> On Monday, October 16, 2017 at 4:33:02 PM UTC-6, French Fry wrote:
>>>>
>>>> I've tried a number of things with no effect.  The call to validation 
>>>> errors  is an  undefined method.  Can you please tell me what I am leaving 
>>>> out? 
>>>>
>>>> And if it's okay to double up, since `def new` instantiates a new Song 
>>>> object, I wanted to use `set` in `def create_song` and it would not work.  
>>>> Right now, while it works (minus the validation error issues) it's 
>>>> essentially creating a new Song object twice.  Originally I used insert, 
>>>> so 
>>>> I replaced it with set, and then save, but no go.  Ok, thank you for the 
>>>> help!
>>>>
>>>> class Song < Sequel::Model
>>>>   plugin :validation_helpers
>>>>   self.raise_on_save_failure
>>>>
>>>>   def validate
>>>>     super
>>>>     validates_presence [:title, :length, :released_on, :lyrics]
>>>>   end
>>>> end
>>>>
>>>> def create_song
>>>>     begin
>>>>       @song = Song.create(params[:song])
>>>>     rescue
>>>>     flash[:notice] = @song.errors.full_messages
>>>>     end
>>>>   end
>>>> end
>>>>
>>>> get '/new' do
>>>>   protected!
>>>>   @song = Song.new
>>>>   slim :new_song
>>>> end
>>>>
>>>>
>>>>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to