sto usando i metodi percorso di supporto per generare URL in link_to, e stanno tornando URL formattati in questo modo:Rails creando percorsi malformati con i puntini
http://localhost:3000/tweets.4
quando io li aspettavo di essere formattato in questo modo:
http://localhost:3000/tweets/4
Nota come si utilizza un punto come delimitatore anziché la barra diretta prevista. Il link in alto non risolve la vista corretta, semplicemente ricarica la vista/tweets. Quando modifico manualmente l'URL in modo che sia come il fondo, si apre il corretto/tweets/show /.
La cosa più vicina che ho trovato nella mia ricerca online era che le persone lo incontravano con istruzioni di instradamento nidificate erroneamente, ma non penso che lo farò qui.
Apprezzerei qualsiasi aiuto o suggerimento che chiunque può fornire!
Ecco il file di origine e le relative informazioni sulla versione:
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'
sto usando Rails 3.2.9 e Ruby 1.9.3p327 (2012/11/10) [x86_64-darwin12.2.0]
duplicato di http://stackoverflow.com/questions/5674116/path-helpers-generate-paths-with-dots- invece di slash –