-- -- wrote:
> I am trying to use link_to_remote to simply add a record to a database
> table called "ratings". I''ve seen some examples of this
being done but
> can''t seem to get it to work. Any ideas about what I''m
doing wrong?
What''s your functional test case look like?
> Here is what I have in my view:
>
> <%= link_to_remote( "1", {:url => { :controller =>
"ratings", :action =>
> "rate", :rateable_id => "1", :rating =>
"1", :rateable_type =>
> "article"}}) %>
>
> Here is what I have in RatingsController:
>
> def rate
> @rating = Rating.new(:rateable_id => params[:rateable_id],
> :rating => params[:rating],
> :rateable_type => params[:rateable_type])
> end
>
> I found that I can successfully write to the database through the
> console with:
>
> rating = Rating.new
> rating.rating = 3
> rating.save
Why don''t you have a save! in the controller? and why you
didn''t use
.create! ?
At a guess, your test case should look a little like this:
fixtures :ratings # this automatically zilches the last test''s
records
def test_new_rate
xhr :get, :rate, :rateable_id => 42, :rating => 1.1,
:rateable_type => ''hot dogs''
rate = Rating.find_by_rateable_id 42
assert_equal ''hot dogs'', rate.rateable_type
end
To put it another way, all the experiments you currently do with the
console, you should instead do as test cases. Then they help you avoid bugs
and develop faster.
--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---