作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用路径辅助方法在 link_to 中生成 URL,它们返回的 URL 格式如下:
http://localhost:3000/tweets.4
http://localhost:3000/tweets/4
<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 %>
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
Zombietweets::Application.routes.draw do
resources :tweets
root :to => 'tweets#index'
end
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'
最佳答案
你试过了吗tweet_path
和 user_path
?
您想访问 show 操作。对于该操作,*_path 调用中的模型名称必须是单数。
可以肯定的是,试试 rake routes
在控制台中。
编辑:
你也忘了加resources :users
在您的路线文件中:)
关于ruby-on-rails - Rails 创建带点的畸形路线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14033853/
我是一名优秀的程序员,十分优秀!