Tôi đang sử dụng phương pháp đường helper để tạo URL trong link_to, và họ đang quay trở lại URL formated như thế này:Rails tạo các tuyến đường bị thay đổi với chấm
http://localhost:3000/tweets.4
khi tôi đã mong họ được formated như thế này:
http://localhost:3000/tweets/4
Lưu ý cách sử dụng dấu chấm làm dấu phân tách thay vì dấu gạch chéo mong đợi. Liên kết trên cùng không giải quyết được chế độ xem chính xác, nó chỉ tải lại chế độ xem/tweets. Khi tôi chỉnh sửa URL theo cách thủ công giống như dưới cùng, nó sẽ mở đúng/tweets/show /.
Điều gần nhất tôi tìm thấy trong nghiên cứu trực tuyến của tôi là mọi người gặp phải điều này với các câu lệnh định tuyến lồng nhau sai - nhưng tôi không nghĩ mình đang làm điều đó ở đây.
Tôi sẽ đánh giá cao bất kỳ trợ giúp hoặc con trỏ nào mà bất kỳ ai cũng có thể cung cấp!
Dưới đây là các file nguồn có liên quan và thông tin phiên bản:
tweets/index.html.erb
<h1>Listing tweets</h1>
<% @tweets.each do |tweet| %>
<div>
<!-- creates path in format of /tweets.2 -->
<div><%= link_to tweet.status, tweets_path(tweet) %></div>
<!-- creates path in the format of /user.1 -->
<div><%= link_to tweet.user.name, users_path(tweet.user) %></div>
</div>
<% end %>
tweets_controller.rb
class TweetsController < ApplicationController
def index
@tweets = Tweet.all
end
def show
@tweet = Tweet.find(params[:id])
end
def new
@tweet = Tweet.new
end
def create
@tweet = Tweet.new(params[:tweet])
@tweet.user = User.last
if(@tweet.save)
redirect_to :root
end
end
def edit
@tweet = Tweet.find(params[:id])
end
def delete
end
end
routes.rb
Zombietweets::Application.routes.draw do
resources :tweets
root :to => 'tweets#index'
end
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.9'
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
end
group :assets do
gem 'sass-rails', '3.2.3'
gem 'coffee-rails', '3.2.1'
gem 'uglifier', '1.0.3'
end
gem 'jquery-rails', '2.0.2'
Tôi đang sử dụng Rails 3.2.9 và Ruby 1.9.3p327 (2012/11/10) [x86_64-darwin12.2.0]
bản sao của http://stackoverflow.com/questions/5674116/path-helpers-generate-paths-with-dots- thay vì-slashes –