Validation error messages help please

I’m having problems with validation error messages appearing in my app.

In Controller:
def permissions
@roles = Role.find(:all, :order => ‘name’)
end

def new_role

@role = Role.create(params[:role])

if request.post? and @role.save

  flash['notice'] = 'Successfully created a new Role'
  redirect_to :action => "permissions"
else
  flash['notice'] = 'The Role was not created. There was an error 

try again’
render :action => ‘permissions’
end
end

Basically I have a permissions page that has a form on it to create new
roles. If the role is created correctly it redirects to the permissions
page and displays the flash. When it fails the display is fine but the
URL now shows “accounts/new_role”. But I am clearly rendering
permissions not new_role. If I change it to “redirect_to” then it
display the “accounts/permissions” page fine but my validation errors do
not display? Anyone shed some light onto what is the correct way please?

Basically I have a permissions page that has a form on it to create new
roles. If the role is created correctly it redirects to the permissions
page and displays the flash. When it fails the display is fine but the
URL now shows “accounts/new_role”. But I am clearly rendering
permissions not new_role. If I change it to “redirect_to” then it
display the “accounts/permissions” page fine but my validation errors do
not display? Anyone shed some light onto what is the correct way please?

That is how it’s supposed to work. :stuck_out_tongue:

The thing is, when you click the submit button you are redirected to the
“new_role” action; when validation fails you’re still in the new_role
action. Then render :action doesn’t change the page: it just renders the
selected action within your current page, and that’s why it displays
your validation errors properly.

I don’t think this can cause any problems, nor do I know of any ways
around it.

-Adam