0
我正在创建一个rails应用程序,我无法弄清楚或找到这个问题的答案。Rails 3:如何编码路径路径
什么是路径:
@example = Example.find_by_notId(params[:notId])
我希望我的路线更好看,然后/例子/ 1,宁愿把它读/ notId(其中notId将标题或其他一些非ID int)。通常我会使用show_path,但在我的HTML <%= link_to image_tag(pic), show_path(example) %>
不起作用。这是我的代码,它在我将其硬编码到URL(localhost:3000/notId)中时起作用,但我需要通过链接路由它。有任何想法吗?
显示
def show
@example = Example.find_by_title(params[:title])
end
路线
match '/:notId', to: 'example#show', via: 'get'
_example.html.erb
<div class="example">
<% Movie.all.each do |example| %>
<%pic = example.title + ".jpg"%>
<%= link_to image_tag(pic), show_path(example) %>
<% end %>
e</div>
谢谢你的工作,我只好把我的html改成'example_path(example.title)' – tzamzow
对,我会用这一点编辑答案。 – markets