王筝的博客
ruby学习

 

http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

creates seven different routes in your application, all mapping to the Photos controller:

HTTP Verb Path Controller#Action Used for
GET /photos photos#index display a list of all photos
GET /photos/new photos#new return an HTML form for creating a new photo
POST /photos photos#create create a new photo
GET /photos/:id photos#show display a specific photo
GET /photos/:id/edit photos#edit return an HTML form for editing a photo
PATCH/PUT /photos/:id photos#update update a specific photo
DELETE /photos/:id photos#destroy delete a specific photo

 

 

vim route.rb

resources :fetched_apps do
member do
patch :import
end
end

 

spring rake routes

recommend_apps GET /recommend_apps(.:format) recommend_apps#index
POST /recommend_apps(.:format) recommend_apps#create

import_fetched_app PATCH  /fetched_apps/:id/import(.:format)     fetched_apps#import

第三条路由需要传入id参数才能拼完整

now let’s figure out the diference between the p_helper.rb and the f_helper.rb

 def render_recommend_info(package, recommend_type_human)
    recommend_type = RecommendApp::TYPES.invert[recommend_type_human]
    recommend_app = package.recommend_apps.where(type: recommend_type).first

    if recommend_app
      url = recommend_app_path(recommend_app)
      clazz = 'fa fa-check-square-o'
      method = :delete
      title = "取消推荐到'#{recommend_type_human}'"
    else
      url = recommend_apps_path(recommend_app: { type: recommend_type, app_id: package.id.to_s })
      clazz = 'fa fa-square-o'
      method = :post
      title = "推荐到'#{recommend_type_human}'"
    end

link_to url, remote: true, method: method, title: title, data: { toggle: ‘tooltip’ } do
content_tag :i, nil, class: clazz
end
end

————————————————

  def render_import_app(fetched_app)
    if fetched_app.already_imported
      url = fetched_app_path(fetched_app)//传入id,可以在controller里取到
      clazz = 'fa fa-check-square-o'
      method = :get
      title = "已导入"
    else
      url = import_fetched_app_path(fetched_app)
      clazz = 'fa fa-square-o'
      method = :patch
      title = "可导入"
    end

    link_to url, remote: true, method: method, title: title, data: { toggle: 'tooltip' } do
      content_tag :i, nil, class: clazz
    end
  end

now turn to the f_controller.rb

def  import
    params[:id]
    .....
end

 

最近的项目里发现一个问题,大师和pp写的index页面就好使,我写index页面就不往index页面跳,总是提示没有show页面,然后上一个项目里,不得不写了个show页面,当~~~这次问了下pp,为啥我的index没有用呢,pp说我路由地址写错了,并教我用下面的语句查看了routes的真实内容。

$ bundle exec rake routes > tempt

$ vim tempt