Friday, November 4, 2011

[Rails] Re: Validate in a model using a controller def

What I mean by "def" is the basic CRUD that rails provide

def create
....
end

def update
...
end

def new
...
end

I want that the data validates in 2 cases (create / update)
because when I want to update , for example:

Evaluation 1
- Question 1

If I update question 1 and change the content, and then I save
it shows a error message that says "The number is being used" (and
that shows that
validates_uniqueness_of :qnumber, :scope works)
I want that it only validates it when I'm CREATING a new one, not when
I'm UPDATING

How can I do that?

On 4 nov, 10:55, Colin Law <clan...@googlemail.com> wrote:
> On 4 November 2011 15:40, JavierQQ <jquari...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > Hi
>
> > I hope someone can help me with this
>
> > I have a model Question, and its controller .. what I've done to
> > validate that there's no evaluation with 2 question with the same
> > number is
>
> >          validates_uniqueness_of :qnumber, :scope
> > => :evaluation_id
>
> > but when I try to update a question's content I got an error message
> > that says that "#{qnumber} has already been taken"
> > and that means that the validation works, but not as I want
>
> > Can I obtain wich "def" is using ? because I want to do this
> > - Question Model
>
> >           IF ("def create" or something)
> >                 do the validation
> >           elsif ("def update")
> >                 don't do it
> >          end
>
> I don't know what you mean by "def" but if you want to do conditional
> validations have a look at the Rails Guide on validations and it will
> show you how.
>
> Colin

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate