我有一个User模型,它与Post模型有一个has_many关系。
Class User < ActiveRecord::Base
has_many :posts
end
Class Post < ActiveRecord::Base
attr_accessor :user_id
belongs_to :user
end
我想设置我的帖子模型的url,其中帖子所有者的名字放在第一位,后面跟着帖子的名称:
localhost:3000/john/sample-post
我尝试在post模型中的slug_candidates方法中设置它,但得到了错误:
Class Po
使用Rails 3中的路由,使用命名空间路由,如下例所示.
namespace :admin do
get 'dashboard' => 'dashboard#index'
end
...how我可以让'/admin‘路由到'dashboard#index’以及‘/admin/仪表板’吗?最好的方法是定义..。
get 'admin' => 'admin/dashboard#index'
在名称空间之外,还是有一种更优雅的方法来别名资源?
到目前为止,我的应用程序似乎还在工作,直到我试着在Heroku上看到它。检查我的日志我看到“错误:(没有路由匹配得到”/“)”.
这是我的routes.rb:
Rails.application.routes.draw do
get 'pages/landing_page'
get 'pages/contact'
get 'pages/about'
这是Gemfile:
Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
g
在从beta升级到RC1之后,我在路由方面遇到了一些问题。有些路线运行良好,而另一些路线给了我以下例外:
Error: Uncaught (in promise): EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: No provider for Router!
ORIGINAL STACKTRACE:
Error: DI Exception
这是我的app.component.ts:
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html
当我试图加载用户的显示视图时,它会得到错误的Couldn't find User with 'id'=
它特别指向第二行在UsersController中。
def show
@user = User.find(params[:id]) ## shows the error in this line
end
有趣的是,使用加载,直到我将路由更改为:
Rails.application.routes.draw do
devise_for :users
get 'users/show'
root 'users#show'
g
我正在使用rails 4.1.1和ruby 2.1.1,并且我的设计有问题,也就是我的路线。
devise_for :users
get 'pages/index'
# Route to Devise Login Page
devise_scope :user do
root to: "devise/sessions#new"
end
# Directing the user after login
authenticated :user do
root :to => 'pages#index'
end
我正在尝试使用Passenger部署一个Rails应用程序。我遵循这个指南:并安装了我所有的gem,但是当我转到我的应用程序应该在的位置时,我发现
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
我知道这并不是很多的信息,但我不知道现在该怎么做。我从哪里开始解决这个问题呢?
编辑:这在日志中
Started GET "/rideboard" for 173.64.211.61 at 2012-07-31 1
我刚开始使用Rails。我遵循Treehouse“构建一个简单的Rails应用程序”教程。直到刚才一切都很顺利。
我正在尝试生成设计视图,但是当我转到localhost:3000/user/sign时,我会看到一个错误:
Routing Error
No route matches [GET] "/"
Try running rake routes for more information on available routes.
当我转到用户/登录、用户/登录时,但当我转到用户/编辑时,就会发生这种情况。
当我试图访问用户/注册时,终端就会向我回吐。
Started
我正在学习一个使用Rails路径渲染页面的教程(https://blog.teamtreehouse.com/static-pages-ruby-rails)。问题是我得到了一个错误,而不是应该呈现的页面。我不知道我做错了什么,因为实际上只有几个步骤。 我的代码与本教程唯一的区别是微不足道的。我使用的是Videos而不是Pages. 在config/routes.rb中 Rails.application.routes.draw do
# This means that all paths following the pattern:
# /videos/about, /vi