我想使用link_to
重定向选择显示页面。
但是,当我点击此链接时,它会重定向到根页面。
我尝试了不同的方法,但它总是重定向到索引根目录。
<%= link_to 'Detalhes', selection %>
我也尝试过:
<%= link_to 'Detalhes', selection_path(selection) %>
<%= link_to 'Detalhes', selection, :method => :show %>
<%= link_to 'Detalhes', selection, method: :show %>
而且,在routes.rb
:
match '/selections/:id' => 'selections#show', :via => :post
路线,如果需要:
selections GET /selections(.:format) selections#index
POST /selections(.:format) selections#create
new_selection GET /selections/new(.:format) selections#new
edit_selection GET /selections/:id/edit(.:format) selections#edit
selection GET /selections/:id(.:format) selections#show
PUT /selections/:id(.:format) selections#update
DELETE /selections/:id(.:format) selections#destroy
我尝试访问选择时的日志:
Started GET "/selections/1" for 127.0.0.1 at 2013-07-21 09:34:55 -0300
Processing by SelectionsController#show as HTML
Parameters: {"id"=>"1"}
[1m[35mSelection Load (0.2ms)[0m SELECT "selections".* FROM "selections" WHERE "selections"."id" = ? LIMIT 1 [["id", "1"]]
[1m[36mUser Load (0.3ms)[0m [1mSELECT "users".* FROM "users" WHERE "users"."id" = 2 LIMIT 1[0m
[1m[35mRole Load (0.4ms)[0m SELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 2 AND "roles"."name" = 'Administrator' LIMIT 1
[1m[36mRole Load (0.4ms)[0m [1mSELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 2 AND "roles"."name" = 'TeamMaster' LIMIT 1[0m
[1m[35mRole Load (0.4ms)[0m SELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles"."id" = "roles_users"."role_id" WHERE "roles_users"."user_id" = 2 AND "roles"."name" = 'Team' LIMIT 1
[1m[36mCACHE (0.0ms)[0m [1mSELECT "selections".* FROM "selections" WHERE "selections"."id" = ? LIMIT 1[0m [["id", "1"]]
Rendered selections/show.html.erb within layouts/application (1.7ms)
Redirected to http:// localhost:3000/
Completed 302 Found in 34ms (ActiveRecord: 0.0ms)
答案 0 :(得分:0)
正确的实施是:
routes.rb 中的
resources :selections
在你的观点中
link_to 'The text', selection
要验证的事项是: