[英]Dynamically adding pages to rails app
This may be a more fundamental aspect of Rails but I am very new. 这可能是Rails的一个更基本的方面,但我很新。
I have a basic app which is sort of a basic craigslist clone. 我有一个基本的应用程序,它是一种基本的craigslist克隆。
Users - I used devise for this, users can sign up/sign in/sign out/edit their profile. 用户 - 我使用了设计,用户可以注册/登录/注销/编辑他们的个人资料。 Listings - Users can add multiple listings. 列表 - 用户可以添加多个列表。 Currently I have a few basic fields populating the database (title, content, phonenumber, price, location). 目前我有一些基本字段填充数据库(标题,内容,电话号码,价格,位置)。
What I want to be able to do is the following: 我希望能做的是以下内容:
I want to have a page which lists all of the ads. 我想要一个列出所有广告的页面。 Currently I can do this by accessing the database and displaying all the contents. 目前我可以通过访问数据库并显示所有内容来完成此操作。 Like this: 像这样:
<h2>LISTINGS</h2>
<% @users.each do |u| %>
<% u.listings.each do |i|%>
<%=u.email %>
<%=i.title %>
<%=i.content %>
<%=i.number %>
<%=i.price %>
<%=i.location %>
<% end %>
<% end %>
What I want to do is have this page only list the titles, each title would link to the appropriate ad. 我想要做的是让此页面仅列出标题,每个标题将链接到相应的广告。 Users could then access their ad with a URL. 然后,用户可以使用网址访问其广告。 Ideally the URL would be the title similar to what stackoverflow does "IE in the URL the title is included with "-" instead of spaces" but that is a minor concern at this point. 理想情况下,URL将是类似于stackoverflow所做的标题“标题包含在URL中的IE” - “而不是空格”,但这是一个小问题。
How is the best way to go about doing this? 如何做到这一点的最佳方式是什么? I may be using incorrect terminology here as I am having trouble finding information. 我可能在这里使用了不正确的术语,因为我无法找到信息。
I think that you should use as below code - 我认为你应该使用如下代码 -
Eg : 例如:
<% @users.each do |u| %>
<%= link_to u.name, :controller => 'user', :action => 'show', :id => u.id %>
<% end %>
I hope that you can solve your problem by using this way. 我希望你能用这种方式解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.