Rails 3 link_to 部分结构
我想创建一个 link_to
渲染 :partial
。我已经在视图文件夹中存储了两个部分,我在其中调用 link_to
(这是配置文件视图)。下一步是让 JavaScript 加载数据,但我在正确构建 link_to
时遇到了困难。
这就是我所拥有的:
<ul id="infoContainer">
<li><%= link_to render(:partial => "about") do %>About<% end %></li>
<li><%= link_to render(:partial => "other") do %>Other<% end %></li>
</ul>
使用这些,两个部分都在我的 show.html.erb
中呈现,并且链接消失了。
所以我尝试了以下操作:
<ul id="infoContainer">
<li><%= link_to render(:partial => 'about'), :class => "a", :remote => true do %>About<% end %></li>
<li><%= link_to render(:partial => 'other'), :class => "o", :remote => true do %>Other<% end %></li>
</ul>
两个部分仍然显示,并且“关于”/“其他”文本链接仍然不显示。
更新:所以我可能可以使用 link_to 。它只是不渲染任何东西。我想必须用 JavaScript 来解决这个问题。
<li><%= link_to "About", (:partial => 'about'}, {:class => "a"}, :remote => true %></li>
<li><%= link_to "Other", (:partial => 'other'}, {:class => "o"}, :remote => true %></li>
使用上面的 link_to
生成 URL:/profiles/1?partial=about
I want to create a link_to
render :partial
. I have two partials stored already in the view folder in which I call the link_to
(which is the profiles views). Getting the JavaScript to load the data is the next step but I am having trouble structuring the link_to
properly.
Here's what I had:
<ul id="infoContainer">
<li><%= link_to render(:partial => "about") do %>About<% end %></li>
<li><%= link_to render(:partial => "other") do %>Other<% end %></li>
</ul>
Using these, both partials rendered in my show.html.erb
and the links disappeared.
So I tried the following:
<ul id="infoContainer">
<li><%= link_to render(:partial => 'about'), :class => "a", :remote => true do %>About<% end %></li>
<li><%= link_to render(:partial => 'other'), :class => "o", :remote => true do %>Other<% end %></li>
</ul>
Both partials still show and the "About"/"Other" text links still don't show.
UPDATE: So I may have the link_to working. It's just not rendering anything. Gotta fix that with JavaScript I assume.
<li><%= link_to "About", (:partial => 'about'}, {:class => "a"}, :remote => true %></li>
<li><%= link_to "Other", (:partial => 'other'}, {:class => "o"}, :remote => true %></li>
Using the link_to
above makes the URL: /profiles/1?partial=about
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您错误地使用了 link_to - 请检查 API / 文档,
它被称为:
请参阅:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
或许:
rails3 (link_to_remote) 的 link_to 语法和基本 javascript 不起作用在 Rails3 应用程序中?
you're using link_to incorrectly -- please check the API / docs
it's called either:
See:
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to
and perhaps:
link_to syntax with rails3 (link_to_remote) and basic javascript not working in a rails3 app?
如果您想在用户点击时运行 javascript,您可以在 http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-link_to_function
If you want to run javascript when user click on, you can read more at http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-link_to_function