Sam Ward wrote:
>Which tests are failing? Are any tests now passing that were failing,
or vice versa?
I've not done any tests before or since, I got a bit carried away before
I got to the chapter on tests in my book (is that bad of me?).
Yes. You've now discovered why you should do all development
test-first: it makes it much easier to determine when your app is
actually failing, and where your undefined constants are.
So...stop now. Install Autotest, RSpec, Cucumber, and Machinist, and
write comprehensive tests for your application. Don't write another
line of app code till all your tests pass (except what's necessary to
fix existing bugs, of course). Do all further development test-first --
that is, write the tests *before* writing the code that will make them
pass. You'll be a lot happier.
I'm
literally just trying to use the site and picking out errors by hand,
this one is quite obvious as being able to save a Loan basically the
whole point of my site!
You've probably missed something: your stack trace still seems to
involve Rails' transaction code
If I do a project wide case-insensitive search on all files within the
appname directory created by "rails appname", the only instance of
'transaction' is found in this file:
test_helper.rb
self.use_transactional_fixtures = true
I left this alone because I didn't really understand what it was.
That's fine; it should stay as it is. (And the rdoc should tell you
what that is.)
Can we see your current LoansController code for new and create?
def new
@loan = Loan.new
end
def create
@loan = Loan.new(params[:loan])
if @loan.save <<< line 36 (this is not in my code, I just put it
here)
flash[:notice] = "Successfully created loan."
redirect_to items_path
else
render :action => 'new'
end
end
This looks fine.
The model definition would probably help as well.
class Loan < ActiveRecord::Base
#attr_accessible :item_id, :user_id, :from, :to, :status
Did you mean to comment that line out? (It's probably OK to have done
so; just asking.)
belongs_to :item
belongs_to :user
def owner
@item = Item.find(item_id)
User.find(@item.user_id)
end
That's a pretty bad way of doing things if I understand correctly what
you're trying to do. You shouldn't need that method at all.
def borrower
User.find(user_id)
end
Again, unnecessary. Rails' associations will take care of that
automatically.
end
-- ends
Thanks again for your time on this, I am the only person I know using
Ruby and/or Rails,
Then join a local user group if you can!
I would be totally adrift without you guys.
Sam
Best,