0

我有一个 link_to 可以创建一个弹出窗口。它适用于某些页面,但是当我在其他页面上单击它时,它会转到错误的 URI。我的应用架构有问题吗?我希望所有链接都路由到

http://localhost:3000/microposts/361/into_it.

SHARED/_feed_item.html.erb---这行代码正确路由:

<%= link_to "#{feed_item.votes_for} Into it!", into_it_micropost_path(feed_item.id), :onclick => "javascript:window.open('microposts/#{feed_item.id}/into_it','popup','width=350,height=300,top=315,left=200');", id: "feeditemlikes_#{feed_item.id}", remote: true %>

USERS/_vote_feed_item.html.erb--- 在类似页面上它路由到

http://localhost:3000/users/1/microposts/361/into_it

<%= link_to "#{vote_feed_item.votes_for} Into it!", into_it_micropost_path(vote_feed_item.id), :onclick => "javascript:window.open('microposts/#{vote_feed_item.id}/into_it','popup','width=350,height=300,top=315,left=200');", id: "feeditemlikes_#{vote_feed_item.id}", remote: true %>

MICROPOSTS/_micropost.html.erb---在配置文件页面上它路由到

http://localhost:3000/users/microposts/361/into_it

<%= link_to "#{micropost.votes_for} Into it!", into_it_micropost_path(micropost.id), :onclick => "javascript:window.open('microposts/#{micropost.id}/into_it','popup','width=350,height=300,top=315,left=200');", id: "feeditemlikes_#{micropost.id}", remote: true %>

实际上,问题似乎出在 javascript 弹出代码上,有什么提示吗?

4

1 回答 1

0

如果我理解正确,你总是想链接到http://localhost:3000/microposts/361/into_it

然后你应该在你的路径前加上一个斜杠:

"javascript:window.open('/microposts/#{micropost.id}/into_it', ..."

或者更好的是,使用 rails path helper,如下所示:

"javascript:window.open(#{into_it_path(micropost)}, ..."
于 2013-01-14T18:00:08.647 回答