路由及路由参数

<%= link_to 'My Blog', {controller: 'articles', demo: "lidsi"}, class: "blogs", id: "blogs" %>
指向 http://0.0.0.0:3000/articles?demo=lidsi
<a class="blogs" >My Blog</a>

在 {} 里的内容被当作query参数,在{}外面的被当作 html属性。

 

将 ActiveRecord 作为 link_to 或 redirect_to 对象 (参考:http://guides.rubyonrails.org/routing.html#creating-paths-and-urls-from-objects)

<%= link_to 'Ad details', [@magazine, @ad] %>

<%= link_to 'Ad details', url_for([@magazine, @ad]) %>


<%= link_to 'Ad details', magazine_ad_path(@magazine, @ad) %>

controller 是这样的

resources :magazines do
  resources :ads
end

helper 会生成一个 route类似

 article_comment GET    /articles/:article_id/comments/:id(.:format)      comments#show

又如

<%= link_to 'article details', @article %>

指向 article GET    /articles/:id(.:format)       articles#show

@articles 指向  articles GET    /articles(.:format)       articles#index

 

在 erb中 render 跟 partial 有关,而 link_to 才跟 controller 有关。 

 render @object 或 render @collection 请

参考 http://www.cnblogs.com/lemos/p/8493366.html

end

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-07-15
  • 2021-11-10
  • 2021-12-13
  • 2022-12-23
猜你喜欢
  • 2021-07-18
  • 2021-08-02
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案