Colin Law wrote:
...
So what's the best way to debug why the create method is not working
properly? Is there a way to set a global variable that would be viewable
from ruby script/console?
Have a look at the RoR guide on Debugging at
http://guides.rubyonrails.org/
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.
Thanks Colin. I took a look at the link (along with Head First Rails /
Simply 2 Rails and other websites) and I better understand why clicking
on the Submit button is redirecting to http://www.<domain
.com/notes (It's trying to perform a POST action...go REST!). I
tracked this to the create Method and have been playing with this method
thinking that the breakdown is happening here.
I tried using logger.debug since I believe the problem may exist in the
controller,(as mentioned here:
http://jeremyhubert.com/articles/debugging-in-rails.html) but wasn't too
successful with it.
In the mean time, I fired up the console and manually created a new Note
object to verify that there wasn't a problem with the model or my
database. I was able to create a new Note fine and display it on my
homepage with a partial that borrows from the index view of my Notes
object.
In my blogs "new" templtae, I noticed that I passed the action
explicitly with the following statement (blogs works great for me):
<h1> New Blog </h1>
<% form_for(@blog, :url=>{:action=>'create'}) do |f| %>
.
.
etc
I tried passing the "create" action to my "new" note partial (which is
rendered in the index of my blog template) and the interesing thing is
that it redirected back to the "create" method of my blogs controller
and created a new blog entry! (Although it was blank because the columns
in the blogs table are different than the notes table). I thought all I
had to do was pass in the correct controller and then I would be golden:
<h1> New Comment </h1>
<% form_for(note, :url=>{:controller=>"Notes",:action=>'create'}) do |f|
%>
.
.
etc
Unfortunately this did not work out (There was no change in behavior).
I looked at the html source code for my home page to see if the form was
referencing the blogs controller since the note partial is on the blogs
template, but it did not look like it was. I checked it against the
source code for the same project on my local machine (where this partial
works) and the html source code for both forms look the same.
I think the problem may be related to the fact that I am using the
following line to render the partial:
<%= render :partial=>"new_note", :locals=>{:note=>Note.new} %>
Could the problem be that when I submit the form, :note gets
overwritten??