Re: using ActiveRecord::Validations::ClassMethods
Awesome! The only thing more fun than writing code is deleting code. On Fri, May 22, 2009 at 9:09 AM, David Susco wrote: > Thanks guys, > > That helped get rid of a lot of code. > > Dave > > On Thu, May 21, 2009 at 10:22 AM, Magnus Holm wrote: >> params is simply Rails' version of @input. >> If you name your keys "user[id]" and "user[name]" in the HTML, then >> @input.user should contain a Hash like { 'id' => ..., 'name' => ... } (maybe >> the keys are Symbols; I don't remember at the moment) >> //Magnus Holm >> >> >> On Thu, May 21, 2009 at 15:50, David Susco wrote: >>> >>> Thanks, I've gotten it to work. >>> >>> On this part though: @user = User.new params[:user >>> >>> Is the closing bracket missing? Is params something from Rails that >>> allows you to create the user instance variable all in one line >>> instead of doing something like this: >>> >>> @user = User.new( >>> :id => input.id, >>> :name => input.name, >>> ... >>> ) >>> >>> Can I use it in a camping app relatively easily? >>> >>> Dave >>> >>> On Wed, May 20, 2009 at 5:27 PM, Eric Mill wrote: >>> > In my create actions, I customarily do like >>> > >>> > @user = User.new params[:user >>> > if @user.save >>> > ... >>> > else >>> > ... >>> > end >>> > >>> > But update_attributes should also return true or false, I believe. >>> > >>> > On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: >>> >> So, in my crud controllers, should I be using calls to save instead of >>> >> create and update_attributes? As those just return the object, and not >>> >> true of false based on my validations. >>> >> >>> >> Dave >>> >> >>> >> On Wed, May 20, 2009 at 4:30 PM, Eric Mill >>> >> wrote: >>> >>> Yeah, but in practice, you'd call @user.save, which internally calls >>> >>> #valid?, and returns true or false on whether the object was saved or >>> >>> not. If the object wasn't saved, @user.errors is populated with the >>> >>> error messages. >>> >>> >>> >>> -- Eric >>> >>> >>> >>> On Wed, May 20, 2009 at 4:03 PM, Magnus Holm >>> >>> wrote: >>> I'm a little rusty on AR at the moment, but I think it looks >>> something like >>> this: >>> In the controller: >>> if @user.valid? >>> # everything is fine >>> else >>> # ops! @user.errors contains the errors >>> end >>> //Magnus Holm >>> >>> >>> On Wed, May 20, 2009 at 19:43, David Susco wrote: >>> > >>> > Can ActiveRecord::Validations::ClassMethods be used to provide >>> > feedback to the user? I noticed the tepee example uses >>> > "validates_uniqueness_of ". If the title isn't unique however >>> > nothing >>> > is written and the user is never notified. >>> > >>> > Does anyone have an example or two of how I could go about informing >>> > the user that the title they entered was not unique and they need to >>> > enter another? >>> > >>> > -- >>> > Dave >>> > ___ >>> > Camping-list mailing list >>> > Camping-list@rubyforge.org >>> > http://rubyforge.org/mailman/listinfo/camping-list >>> >>> >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >>> >>> >>> ___ >>> >>> Camping-list mailing list >>> >>> Camping-list@rubyforge.org >>> >>> http://rubyforge.org/mailman/listinfo/camping-list >>> >>> >>> >> >>> >> >>> >> >>> >> -- >>> >> Dave >>> >> ___ >>> >> Camping-list mailing list >>> >> Camping-list@rubyforge.org >>> >> http://rubyforge.org/mailman/listinfo/camping-list >>> >> >>> > ___ >>> > Camping-list mailing list >>> > Camping-list@rubyforge.org >>> > http://rubyforge.org/mailman/listinfo/camping-list >>> > >>> >>> >>> >>> -- >>> Dave >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >> >> >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > > > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
Thanks guys, That helped get rid of a lot of code. Dave On Thu, May 21, 2009 at 10:22 AM, Magnus Holm wrote: > params is simply Rails' version of @input. > If you name your keys "user[id]" and "user[name]" in the HTML, then > @input.user should contain a Hash like { 'id' => ..., 'name' => ... } (maybe > the keys are Symbols; I don't remember at the moment) > //Magnus Holm > > > On Thu, May 21, 2009 at 15:50, David Susco wrote: >> >> Thanks, I've gotten it to work. >> >> On this part though: @user = User.new params[:user >> >> Is the closing bracket missing? Is params something from Rails that >> allows you to create the user instance variable all in one line >> instead of doing something like this: >> >> @user = User.new( >> :id => input.id, >> :name => input.name, >> ... >> ) >> >> Can I use it in a camping app relatively easily? >> >> Dave >> >> On Wed, May 20, 2009 at 5:27 PM, Eric Mill wrote: >> > In my create actions, I customarily do like >> > >> > @user = User.new params[:user >> > if @user.save >> > ... >> > else >> > ... >> > end >> > >> > But update_attributes should also return true or false, I believe. >> > >> > On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: >> >> So, in my crud controllers, should I be using calls to save instead of >> >> create and update_attributes? As those just return the object, and not >> >> true of false based on my validations. >> >> >> >> Dave >> >> >> >> On Wed, May 20, 2009 at 4:30 PM, Eric Mill >> >> wrote: >> >>> Yeah, but in practice, you'd call @user.save, which internally calls >> >>> #valid?, and returns true or false on whether the object was saved or >> >>> not. If the object wasn't saved, @user.errors is populated with the >> >>> error messages. >> >>> >> >>> -- Eric >> >>> >> >>> On Wed, May 20, 2009 at 4:03 PM, Magnus Holm >> >>> wrote: >> I'm a little rusty on AR at the moment, but I think it looks >> something like >> this: >> In the controller: >> if @user.valid? >> # everything is fine >> else >> # ops! @user.errors contains the errors >> end >> //Magnus Holm >> >> >> On Wed, May 20, 2009 at 19:43, David Susco wrote: >> > >> > Can ActiveRecord::Validations::ClassMethods be used to provide >> > feedback to the user? I noticed the tepee example uses >> > "validates_uniqueness_of ". If the title isn't unique however >> > nothing >> > is written and the user is never notified. >> > >> > Does anyone have an example or two of how I could go about informing >> > the user that the title they entered was not unique and they need to >> > enter another? >> > >> > -- >> > Dave >> > ___ >> > Camping-list mailing list >> > Camping-list@rubyforge.org >> > http://rubyforge.org/mailman/listinfo/camping-list >> >> >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> >> >>> ___ >> >>> Camping-list mailing list >> >>> Camping-list@rubyforge.org >> >>> http://rubyforge.org/mailman/listinfo/camping-list >> >>> >> >> >> >> >> >> >> >> -- >> >> Dave >> >> ___ >> >> Camping-list mailing list >> >> Camping-list@rubyforge.org >> >> http://rubyforge.org/mailman/listinfo/camping-list >> >> >> > ___ >> > Camping-list mailing list >> > Camping-list@rubyforge.org >> > http://rubyforge.org/mailman/listinfo/camping-list >> > >> >> >> >> -- >> Dave >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list > > > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -- Dave ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
params is simply Rails' version of @input. If you name your keys "user[id]" and "user[name]" in the HTML, then @input.user should contain a Hash like { 'id' => ..., 'name' => ... } (maybe the keys are Symbols; I don't remember at the moment) //Magnus Holm On Thu, May 21, 2009 at 15:50, David Susco wrote: > Thanks, I've gotten it to work. > > On this part though: @user = User.new params[:user > > Is the closing bracket missing? Is params something from Rails that > allows you to create the user instance variable all in one line > instead of doing something like this: > > @user = User.new( > :id => input.id, > :name => input.name, > ... > ) > > Can I use it in a camping app relatively easily? > > Dave > > On Wed, May 20, 2009 at 5:27 PM, Eric Mill wrote: > > In my create actions, I customarily do like > > > > @user = User.new params[:user > > if @user.save > > ... > > else > > ... > > end > > > > But update_attributes should also return true or false, I believe. > > > > On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: > >> So, in my crud controllers, should I be using calls to save instead of > >> create and update_attributes? As those just return the object, and not > >> true of false based on my validations. > >> > >> Dave > >> > >> On Wed, May 20, 2009 at 4:30 PM, Eric Mill > wrote: > >>> Yeah, but in practice, you'd call @user.save, which internally calls > >>> #valid?, and returns true or false on whether the object was saved or > >>> not. If the object wasn't saved, @user.errors is populated with the > >>> error messages. > >>> > >>> -- Eric > >>> > >>> On Wed, May 20, 2009 at 4:03 PM, Magnus Holm > wrote: > I'm a little rusty on AR at the moment, but I think it looks something > like > this: > In the controller: > if @user.valid? > # everything is fine > else > # ops! @user.errors contains the errors > end > //Magnus Holm > > > On Wed, May 20, 2009 at 19:43, David Susco wrote: > > > > Can ActiveRecord::Validations::ClassMethods be used to provide > > feedback to the user? I noticed the tepee example uses > > "validates_uniqueness_of ". If the title isn't unique however nothing > > is written and the user is never notified. > > > > Does anyone have an example or two of how I could go about informing > > the user that the title they entered was not unique and they need to > > enter another? > > > > -- > > Dave > > ___ > > Camping-list mailing list > > Camping-list@rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > > >>> ___ > >>> Camping-list mailing list > >>> Camping-list@rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/camping-list > >>> > >> > >> > >> > >> -- > >> Dave > >> ___ > >> Camping-list mailing list > >> Camping-list@rubyforge.org > >> http://rubyforge.org/mailman/listinfo/camping-list > >> > > ___ > > Camping-list mailing list > > Camping-list@rubyforge.org > > http://rubyforge.org/mailman/listinfo/camping-list > > > > > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
Hah, yeah, the bracket is missing. And in Camping, the equivalent of Rails' "params" is "@input". -- Eric On Thu, May 21, 2009 at 9:50 AM, David Susco wrote: > Thanks, I've gotten it to work. > > On this part though: @user = User.new params[:user > > Is the closing bracket missing? Is params something from Rails that > allows you to create the user instance variable all in one line > instead of doing something like this: > > @user = User.new( > :id => input.id, > :name => input.name, > ... > ) > > Can I use it in a camping app relatively easily? > > Dave > > On Wed, May 20, 2009 at 5:27 PM, Eric Mill wrote: >> In my create actions, I customarily do like >> >> @user = User.new params[:user >> if @user.save >> ... >> else >> ... >> end >> >> But update_attributes should also return true or false, I believe. >> >> On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: >>> So, in my crud controllers, should I be using calls to save instead of >>> create and update_attributes? As those just return the object, and not >>> true of false based on my validations. >>> >>> Dave >>> >>> On Wed, May 20, 2009 at 4:30 PM, Eric Mill wrote: Yeah, but in practice, you'd call @user.save, which internally calls #valid?, and returns true or false on whether the object was saved or not. If the object wasn't saved, @user.errors is populated with the error messages. -- Eric On Wed, May 20, 2009 at 4:03 PM, Magnus Holm wrote: > I'm a little rusty on AR at the moment, but I think it looks something > like > this: > In the controller: > if @user.valid? > # everything is fine > else > # ops! @user.errors contains the errors > end > //Magnus Holm > > > On Wed, May 20, 2009 at 19:43, David Susco wrote: >> >> Can ActiveRecord::Validations::ClassMethods be used to provide >> feedback to the user? I noticed the tepee example uses >> "validates_uniqueness_of ". If the title isn't unique however nothing >> is written and the user is never notified. >> >> Does anyone have an example or two of how I could go about informing >> the user that the title they entered was not unique and they need to >> enter another? >> >> -- >> Dave >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list > > > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list >>> >>> >>> >>> -- >>> Dave >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >>> >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > > > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
Thanks, I've gotten it to work. On this part though: @user = User.new params[:user Is the closing bracket missing? Is params something from Rails that allows you to create the user instance variable all in one line instead of doing something like this: @user = User.new( :id => input.id, :name => input.name, ... ) Can I use it in a camping app relatively easily? Dave On Wed, May 20, 2009 at 5:27 PM, Eric Mill wrote: > In my create actions, I customarily do like > > @user = User.new params[:user > if @user.save > ... > else > ... > end > > But update_attributes should also return true or false, I believe. > > On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: >> So, in my crud controllers, should I be using calls to save instead of >> create and update_attributes? As those just return the object, and not >> true of false based on my validations. >> >> Dave >> >> On Wed, May 20, 2009 at 4:30 PM, Eric Mill wrote: >>> Yeah, but in practice, you'd call @user.save, which internally calls >>> #valid?, and returns true or false on whether the object was saved or >>> not. If the object wasn't saved, @user.errors is populated with the >>> error messages. >>> >>> -- Eric >>> >>> On Wed, May 20, 2009 at 4:03 PM, Magnus Holm wrote: I'm a little rusty on AR at the moment, but I think it looks something like this: In the controller: if @user.valid? # everything is fine else # ops! @user.errors contains the errors end //Magnus Holm On Wed, May 20, 2009 at 19:43, David Susco wrote: > > Can ActiveRecord::Validations::ClassMethods be used to provide > feedback to the user? I noticed the tepee example uses > "validates_uniqueness_of ". If the title isn't unique however nothing > is written and the user is never notified. > > Does anyone have an example or two of how I could go about informing > the user that the title they entered was not unique and they need to > enter another? > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >>> >> >> >> >> -- >> Dave >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -- Dave ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
In my create actions, I customarily do like @user = User.new params[:user if @user.save ... else ... end But update_attributes should also return true or false, I believe. On Wed, May 20, 2009 at 4:42 PM, David Susco wrote: > So, in my crud controllers, should I be using calls to save instead of > create and update_attributes? As those just return the object, and not > true of false based on my validations. > > Dave > > On Wed, May 20, 2009 at 4:30 PM, Eric Mill wrote: >> Yeah, but in practice, you'd call @user.save, which internally calls >> #valid?, and returns true or false on whether the object was saved or >> not. If the object wasn't saved, @user.errors is populated with the >> error messages. >> >> -- Eric >> >> On Wed, May 20, 2009 at 4:03 PM, Magnus Holm wrote: >>> I'm a little rusty on AR at the moment, but I think it looks something like >>> this: >>> In the controller: >>> if @user.valid? >>> # everything is fine >>> else >>> # ops! @user.errors contains the errors >>> end >>> //Magnus Holm >>> >>> >>> On Wed, May 20, 2009 at 19:43, David Susco wrote: Can ActiveRecord::Validations::ClassMethods be used to provide feedback to the user? I noticed the tepee example uses "validates_uniqueness_of ". If the title isn't unique however nothing is written and the user is never notified. Does anyone have an example or two of how I could go about informing the user that the title they entered was not unique and they need to enter another? -- Dave ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list >>> >>> >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >>> >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > > > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
So, in my crud controllers, should I be using calls to save instead of create and update_attributes? As those just return the object, and not true of false based on my validations. Dave On Wed, May 20, 2009 at 4:30 PM, Eric Mill wrote: > Yeah, but in practice, you'd call @user.save, which internally calls > #valid?, and returns true or false on whether the object was saved or > not. If the object wasn't saved, @user.errors is populated with the > error messages. > > -- Eric > > On Wed, May 20, 2009 at 4:03 PM, Magnus Holm wrote: >> I'm a little rusty on AR at the moment, but I think it looks something like >> this: >> In the controller: >> if @user.valid? >> # everything is fine >> else >> # ops! @user.errors contains the errors >> end >> //Magnus Holm >> >> >> On Wed, May 20, 2009 at 19:43, David Susco wrote: >>> >>> Can ActiveRecord::Validations::ClassMethods be used to provide >>> feedback to the user? I noticed the tepee example uses >>> "validates_uniqueness_of ". If the title isn't unique however nothing >>> is written and the user is never notified. >>> >>> Does anyone have an example or two of how I could go about informing >>> the user that the title they entered was not unique and they need to >>> enter another? >>> >>> -- >>> Dave >>> ___ >>> Camping-list mailing list >>> Camping-list@rubyforge.org >>> http://rubyforge.org/mailman/listinfo/camping-list >> >> >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list >> > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > -- Dave ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
Yeah, but in practice, you'd call @user.save, which internally calls #valid?, and returns true or false on whether the object was saved or not. If the object wasn't saved, @user.errors is populated with the error messages. -- Eric On Wed, May 20, 2009 at 4:03 PM, Magnus Holm wrote: > I'm a little rusty on AR at the moment, but I think it looks something like > this: > In the controller: > if @user.valid? > # everything is fine > else > # ops! @user.errors contains the errors > end > //Magnus Holm > > > On Wed, May 20, 2009 at 19:43, David Susco wrote: >> >> Can ActiveRecord::Validations::ClassMethods be used to provide >> feedback to the user? I noticed the tepee example uses >> "validates_uniqueness_of ". If the title isn't unique however nothing >> is written and the user is never notified. >> >> Does anyone have an example or two of how I could go about informing >> the user that the title they entered was not unique and they need to >> enter another? >> >> -- >> Dave >> ___ >> Camping-list mailing list >> Camping-list@rubyforge.org >> http://rubyforge.org/mailman/listinfo/camping-list > > > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
Re: using ActiveRecord::Validations::ClassMethods
I'm a little rusty on AR at the moment, but I think it looks something like this: In the controller: if @user.valid? # everything is fine else # ops! @user.errors contains the errors end //Magnus Holm On Wed, May 20, 2009 at 19:43, David Susco wrote: > Can ActiveRecord::Validations::ClassMethods be used to provide > feedback to the user? I noticed the tepee example uses > "validates_uniqueness_of ". If the title isn't unique however nothing > is written and the user is never notified. > > Does anyone have an example or two of how I could go about informing > the user that the title they entered was not unique and they need to > enter another? > > -- > Dave > ___ > Camping-list mailing list > Camping-list@rubyforge.org > http://rubyforge.org/mailman/listinfo/camping-list > ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list
using ActiveRecord::Validations::ClassMethods
Can ActiveRecord::Validations::ClassMethods be used to provide feedback to the user? I noticed the tepee example uses "validates_uniqueness_of ". If the title isn't unique however nothing is written and the user is never notified. Does anyone have an example or two of how I could go about informing the user that the title they entered was not unique and they need to enter another? -- Dave ___ Camping-list mailing list Camping-list@rubyforge.org http://rubyforge.org/mailman/listinfo/camping-list