【问题标题】:Rails: How to add User ID into a linkRails:如何将用户 ID 添加到链接中
【发布时间】:2012-03-07 01:06:53
【问题描述】:

我有这个 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...
...                               ^

【问题讨论】:

  • @rwilliams 您在工作之前的回复:)

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


【解决方案1】:

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

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

【讨论】:

  • 工作就像一个魅力,我只是不确定如何插入该 user.id。谢谢你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-12
相关资源
最近更新 更多