My entire code :
<% query.inline_columns.each do|column| %>
<% if column.css_classes.to_s != "assigned_to" %>
<td class="<%= column.css_classes %>"> <%= column_content(column, issue) %> </td>
<% else %>
<td class="<%= column.css_classes %>"> <%= test = column_content(column, issue) %> </td>
<% end %>
<% end %>
I have something like that:
test = column_content(column, issue)
and when i go on the website it give me something like that:
<a class="user active" href="/users/5">Test</a>
My question is how can I get the value of href ? I tried test.href, test.link_to and test.link but don't work.
And after when we have the href it's possible to only have the id in href ? (In the href above it's 5) BUT I don't want to go on page and get the id, I just want to have it so I can load the picture of user in the table.
I'm beginner in ERB language, thank's for help !
EDIT: My solution to get the id :
test.to_s.split("href=\"").last.to_s.split("\"").first.to_s.split("/").last.to_s
Thank's guy to try to help me !
答案 0 :(得分:0)
在Rails和MVC中,每个请求都遵循一个循环:
假设您输入http://localhost:3000/users
。
UsersController#index
并呈现视图。那我为什么告诉你这个?
ERB
无关。您只需渲染视图并将其发送到客户端 - 全部完成。客户可以通过单击链接或提交表单进行交互。但这并不是你真实的观点。
当用户点击链接时,它会启动一个全新的请求 - 这是一个全新的流程*。
路线有点像正则表达式 - 超级大国。
如果您希望rails应用程序处理/users/1
的请求,则需要创建路径:
# config/routes.rb
get `/users/:id`, to: 'users#show'
请参阅:id
部分?这意味着我们可以从params[:id]
获取在网址中传递的ID。
class UsersController
def show
@user = User.find(params[:id])
end
end
当然,写这样的路线非常繁琐。所以我们写一下:
resources :users
尝试从控制台运行rake routes
以查看其功能。