Hi list, I''ve started migrating to rails 3 and right now I''m getting to grips with the different methods for handling validation error message. I''ve found this on asciiguides which seems good, the first code examples which move the error display handling to a partial: http://asciicasts.com/episodes/211-validations-in-rails-3 Which works perfectly for the new and create actions, however on the edit and update actions it gives me the following, referring to the first line of the partial: undefined local variable or method `target'' for #<#<Class:0xb6459528>:0xb645683c> The only difference between the new/create and the edit/update actions is the formers uses @model.save and the latter @model.update_attributes. If I take out the refence to the partial, replacing the model name back in, everything works fine but really isn''t DRY. I can post full code examples if necessary. Thanks Matt
On Sun, Apr 17, 2011 at 5:01 PM, Matt Harrison <iwasinnamuknow-ja4MoDZtUtVl57MIdRCFDg@public.gmane.org> wrote:> > I can post full code examples if necessary. > >That would be extremely helpful. B. -- 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.
On Mon, Apr 18, 2011 at 07:51:49AM -0500, Bryan Crossland wrote:> On Sun, Apr 17, 2011 at 5:01 PM, Matt Harrison <iwasinnamuknow@genestate.com > > wrote: > > > > > I can post full code examples if necessary. > > > > > That would be extremely helpful.Ok, here is the controller code: http://pastie.org/1807523 And the views: http://pastie.org/1807530 And the partial: http://pastie.org/1807536 new/update works perfectly, while edit/update gives this error while visiting the edit action: http://pastie.org/1807548 If I change the edit view to look like the following, it works fine: http://pastie.org/1807558 But I don''t want to have to do that for every view. As you can tell I''m no expert and I''m a bit stumped. Grateful for some tips Thanks
On Mon, Apr 18, 2011 at 10:47 AM, Matt Harrison < iwasinnamuknow-ja4MoDZtUtVl57MIdRCFDg@public.gmane.org> wrote:> On Mon, Apr 18, 2011 at 07:51:49AM -0500, Bryan Crossland wrote: > > On Sun, Apr 17, 2011 at 5:01 PM, Matt Harrison < > iwasinnamuknow-ja4MoDZtUtVl57MIdRCFDg@public.gmane.org > > > wrote: > > > > > > > > I can post full code examples if necessary. > > > > > > > > That would be extremely helpful. > > Ok, here is the controller code: > > http://pastie.org/1807523 > > And the views: > > http://pastie.org/1807530 > > And the partial: > > http://pastie.org/1807536 > > > new/update works perfectly, while edit/update gives this error while > visiting the edit > action: > > http://pastie.org/1807548 > > > If I change the edit view to look like the following, it works fine: > > http://pastie.org/1807558 > > But I don''t want to have to do that for every view. As you can tell I''m no > expert and > I''m a bit stumped. Grateful for some tips > > Thanks >I think the issue is that you need to remove :partial=> from your Edit Category view. When you are specifying :partial hash param it is ignoring :target and expecting something else, like collection, to be passed in. If you change your Edit to be like what is below it should work. Change from this: = render :partial => "shared/error_messages", :target => @category To this: = render "shared/error_messages", :target => @category B. -- 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.
On Mon, Apr 18, 2011 at 10:44:08PM -0500, Bryan Crossland wrote:> I think the issue is that you need to remove :partial=> from your Edit > Category view. When you are specifying :partial hash param it is ignoring > :target and expecting something else, like collection, to be passed in. If > you change your Edit to be like what is below it should work. > > Change from this: > > = render :partial => "shared/error_messages", :target => @category > > To this: > > = render "shared/error_messages", :target => @category > > B.Thanks Bryan, That was exactly the problem. I had looked at the edit views vs the new views so many times. I just didn''t notice that they differed as you showed above. I thought I''d copied and pasted so I really didn''t expect them to be different. Thanks again