That’s not quite how it works: all the attributes and so on are
changed and so on, so foo.some_attribute does return the new data
(even though it hasn’t hit the database yet) (or have I missed the
What I’m trying to do (which may or may not be correct), is create a
validator within my model file: story.rb, that checks to see if the
member has enough credits to pay for his or her story post. The only
way I can do this is if I knew how much money the member has in his or
her account. However, I don’t know how to pull that data from within
the story model (if it’s possible / the Rails way to do so).
(This is per my current knowledge): When a member submits a form, that
form should go to the create action from within the controller. When
you try to save the data to the database, it’s checked against the
validators within the model and either returns true or false. Thus,
the story model should receive and check the data from the form. If
that’s true, is there a way to see what data the model is handling?
Perhaps I should be doing this check from within the controller? Such
@story = Story.new(params[:story])
@story.member_id = current_user.id
unless current_user.credits >= (@story.credits *
errors.add_to_base(“You do not have enough credits to post this
flash[:notice] = ‘Story was successfully created.’
render :action => “new”
I haven’t tried this code. I figure it will work (probably with a few
adjustments), though am not sure it’s the Rails way. I’m under the
impression that all validation should be done within the model. Is
this correct thinking, or is what I have above okay?
Thanks for your help Frederick. You always seem to be close whenever
I’m plagued with my many questions.