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)