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:
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.
That would be extremely helpful.
Ok, here is the controller code:
And the views:
And the partial:
new/update works perfectly, while edit/update gives this error while visiting the edit
If I change the edit view to look like the following, it works fine:
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
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
= render "shared/error_messages", :target => @category
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.