I need to do an html delete if the record isn''t saved, so in Rails 2,
all I had to do was:
<% if person_form.object.new_record? %>
<%= link_to_function "Delete", "delete_row()"
%>
<% else %>
....
object doesn''t seem to be there, and rails 3 seems angry about the
fields_for that defines person_form in Rails 2.
I''m trying to do this in Rails 3 and having no luck.. Please help
Thanks
Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud --
2011-Aug-03 05:37 UTC
Re: Looking for way to test for an unsaved record in Rails 3
Both ActionView::Helpers::FormBuilder#object() and
ActiveRecord::Persistence#new_record?() exist in rails 3. Here is how
"Ruby on Rails 3 Tutorial" uses them:
<%= form_for(@user) do |f| %>
<%= render ''some/partial'', :object => f.object %>
Then a local variable named ''object'' is available in the
partial and it
is equal to @user (at least that is the way things appear to work).
class User < ActiveRecordBase
...
...
def some_action
if new_record?
#do something
end
end
> and rails 3 seems angry about the
> fields_for that defines person_form in Rails 2
You should post your code.
--
Posted via http://www.ruby-forum.com/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.