Rails:如何将用户ID添加到链接中

时间:2012-03-07 01:06:54

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-3.1

我有这个will_paginate用于微博链接,我正在尝试将<%= user.id %>添加到此base_link_url中,但user.id将无效。有没有办法可以将user.id添加到此而不会收到错误?

链接

<%= will_paginate microposts, :renderer => CustomLinkRenderer, :base_link_url => "/users/<%= user.id %>", :page_links => false , :class =>"pagination" %>

对于那些对此我感兴趣的人,它来自这里:

Issue with will_paginate page links

错误

/Users/Brian/rails_projects/project/app/views/users/_microposts.html.erb:4: syntax error, unexpected '>'
/Users/Brian/rails_projects/project/app/views/users/_microposts.html.erb:6: syntax error, unexpected keyword_class, expecting keyword_do or '{' or '('
..._buffer.safe_concat('<div class="EmptyContainer"><span class...
...                               ^
/Users/Brian/rails_projects/project/app/views/users/_microposts.html.erb:6: syntax error, unexpected '<'
...('<div class="EmptyContainer"><span class=\'Empty\'>Add a th...
...                               ^

1 个答案:

答案 0 :(得分:2)

试一试。我认为你没有正确地将user.id变量插入到该语句中。

<%= will_paginate microposts, :renderer => CustomLinkRenderer, :base_link_url => "/users/#{user.id}", :page_links => false , :class =>"pagination" %>