开发者

Rails 3 - custom url in block not working

开发者 https://www.devze.com 2023-04-01 05:06 出处:网络
I am trying to use: <% @deal.tasks.each do |task| %> <li id=\"task_<%= task.id %>\"> <span class=\"handle\">[drag]</span>

I am trying to use:

<% @deal.tasks.each do |task| %>
<li id="task_<%= task.id %>">
    <span class="handle">[drag]</span>
    <%= link_to "#{task.title}", deal_task_url(:id => task.id) %>  
</li>
<% end %>

in my routes...

match "tasks/:id" => "tasks#show", :as => "deal_task"

So the error i get is that task.id is nil, i can put task.id anywhere else in the block and it is the correct value, however when it's inside deal_task_url it is always nil.

Now, as a test to make sure my route worked, and was what I wanted, i did this...

开发者_JS百科<%= link_to "#{task.title}", deal_task_url(:id => '1') %>

It worked, but obviously every result had the same link.

So my question is 2 parts.

Part 1 - Why doesn't this work

deal_task_url(:id => task.id)

Part 2 - - How would I get the task.id into the deal_task_url()

Thanks in advance!


Simply do:

deal_task_url(task.id)
0

精彩评论

暂无评论...
验证码 换一张
取 消