Ruby RoR未定义方法
我有一个问题好几天了。我在stackoverflow上找到的所有solotion thad都试过了,但都没用 当我尝试添加一个新的“旅程”(仅仅是一个简单的datapase条目)时,Rails给了我一个错误:未定义的方法“旅程\索引\路径”# 问题解决了! 问题是型号名称。这是旅程,但它应该是旅程!我唯一要做的就是在app/models中重命名modelfile。(我不得不更改文件名和内容,非常简单 哦,模型名和数据库名不一样。 请查看更多命名规则 Routes.rb:Ruby RoR未定义方法,ruby,database,ruby-on-rails-3,routes,Ruby,Database,Ruby On Rails 3,Routes,我有一个问题好几天了。我在stackoverflow上找到的所有solotion thad都试过了,但都没用 当我尝试添加一个新的“旅程”(仅仅是一个简单的datapase条目)时,Rails给了我一个错误:未定义的方法“旅程\索引\路径”# 问题解决了! 问题是型号名称。这是旅程,但它应该是旅程!我唯一要做的就是在app/models中重命名modelfile。(我不得不更改文件名和内容,非常简单 哦,模型名和数据库名不一样。 请查看更多命名规则 Routes.rb: Fabulam::App
Fabulam::Application.routes.draw do
root "home#home"
resources :journeys
match 'auth/:provider/callback', to: 'sessions#create', via: 'get'
match 'auth/failure', to: redirect('/'), via: 'get'
match 'signout', to: 'sessions#destroy', via: 'get', as: 'signout'
end
行程控制器(相关部分)
new.html.erb(location=journes/new.html.erb)
我错过什么了吗
提前感谢!此错误发生在哪里(即:是在您转到/Travelies/new时)?请将整个堆栈跟踪添加到您的问题中。请添加整个
routes.rb
文件和控制器操作,至少create
。感谢您的回复!我将使用完整的routes.rb更新我的问题。当我转到“旅行/新建”时会发生错误。
def index
@current_user ||= User.find(session[:user_id]) if session[:user_id]
@journey = Journeys.where(uid: current_user.uid)
end
def show
@journey = Journeys.find(params[:id])
end
def new
@journey = Journeys.new
end
<!DOCTYPE html>
<html>
<body>
<div>
<h1> Maak hieronder een nieuwe reis aan! </h1>
<% form_for(@journey) do |f| %>
<p>
<%= f.label :name %><br/<
<%= f.text_field :name %>
</P>
<p>
<%f.submit "Dubmittt" %>
</p>
<% end %>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<div id="user_nav">
<% if current_user %>
Signed in as <strong><%= current_user.name %></strong>!
<%= link_to "Sign out", signout_path, id: "sign_out" %>
<% else %>
<%= link_to "Sign in with Facebook", "/auth/facebook", id: "sign_in" %>
<% end %>
</div>
<div id="travels">
Hieronder al je reizen!
<% @journey.each do |journey| %>
<h2><%= link_to journey.name, journey %></h2>
<% end %>
</div>
<p><%= link_to "Add a new journey" , new_journey_path %> </P>
</body>
</html>
Prefix Verb URI Pattern Controller#Action
root GET / home#home
journeys GET /journeys(.:format) journeys#index
POST /journeys(.:format) journeys#create
new_journey GET /journeys/new(.:format) journeys#new
edit_journey GET /journeys/:id/edit(.:format) journeys#edit
journey GET /journeys/:id(.:format) journeys#show
PATCH /journeys/:id(.:format) journeys#update
PUT /journeys/:id(.:format) journeys#update
DELETE /journeys/:id(.:format) journeys#destroy
GET /auth/:provider/callback(.:format) sessions#create
auth_failure GET /auth/failure(.:format) redirect(301, /)
signout GET /signout(.:format) sessions#destroy