Lp
2009-Jul-09 14:24 UTC
link_to_unless_current fails when processing forms with error messages in it with restful routes
Hello,
does anyone know how to prevent the failing mechanism of
link_to_unless_current?
f.e.: I have my page navigation with
link_to_unless_current "new task", new_task_path
When I click on the link, i come to the new taks path form... And no
link is created -> ok. Then I put incorrect values in the form and
submit.
The TasksController processes the "create" action, the validation for
the ActiveRecord-model fails because of the incorrect data and the
controller renders the "new" action (and includes the error messages
for the model).
class TasksController < ApplicationController
def create
@task = Task.new(params[:task])
if @task.save
flash[:notice] = ''task was successfully created.''
redirect_to(tasks_url)
else
render :action => "new"
end
end
end
But here the link gets created! -> Because of the difference between
the urls:
link path = new_task_path
but
posted path = tasks_path with :method => :post
Does anybody know how to cleanly solve this problem?
Thanks
Lp
2009-Jul-09 14:52 UTC
Re: link_to_unless_current fails when processing forms with error messages in it with restful routes
ou can do it with link_to_unless instead of link_to_unless_current:
link_to_unless(controller_name == ''tasks'' &&
(action_name == ''new'' || action_name ==
''create''),
new_task_path)
On 9 Jul., 16:24, Lp
<lampesberger.pe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello,
>
> does anyone know how to prevent the failing mechanism of
> link_to_unless_current?
>
> f.e.: I have my page navigation with
>
> link_to_unless_current "new task", new_task_path
>
> When I click on the link, i come to the new taks path form... And no
> link is created -> ok. Then I put incorrect values in the form and
> submit.
>
> The TasksController processes the "create" action, the validation
for
> the ActiveRecord-model fails because of the incorrect data and the
> controller renders the "new" action (and includes the error
messages
> for the model).
>
> class TasksController < ApplicationController
> def create
> @task = Task.new(params[:task])
>
> if @task.save
> flash[:notice] = ''task was successfully
created.''
> redirect_to(tasks_url)
> else
> render :action => "new"
> end
> end
> end
>
> But here the link gets created! -> Because of the difference between
> the urls:
>
> link path = new_task_path
>
> but
>
> posted path = tasks_path with :method => :post
>
> Does anybody know how to cleanly solve this problem?
>
> Thanks