# Link\_to\_unless\_current fails when processing forms with error messages in it with restful routes

**URL:** <https://www.ruby-forum.com/t/link-to-unless-current-fails-when-processing-forms-with-error-messages-in-it-with-restful-routes/171811>\
**Category:** Rails\
**Created:** [July 9, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/link-to-unless-current-fails-when-processing-forms-with-error-messages-in-it-with-restful-routes/171811 "2009-07-09T16:25:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LpLpLp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@LpLpLp](https://www.ruby-forum.com/u/LpLpLp)\
**Post date:** [July 9, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/link-to-unless-current-fails-when-processing-forms-with-error-messages-in-it-with-restful-routes/171811/1 "2009-07-09T16:25:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![LpLpLp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/bc8723/32.png) [@LpLpLp](https://www.ruby-forum.com/u/LpLpLp)\
**Post date:** [July 9, 2009, 4:53pm UTC](https://www.ruby-forum.com/t/link-to-unless-current-fails-when-processing-forms-with-error-messages-in-it-with-restful-routes/171811/2 "2009-07-09T16:53:15Z")

</div>

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)
