RoR未定义的方法

时间:2014-03-22 15:36:49

标签: ruby database ruby-on-rails-3 routes

我已经有几天问题了。我尝试过在stackoverflow上发现的每一个问题,但没有任何效果......

当我尝试添加一个新的旅程时,Rails会给我一个错误。 (只是一个简单的数据库条目):未定义的方法`journeys_index_path'对于#<#:0x3d0b888>

问题解决了! 问题是型号名称。这是旅程,但它应该是旅程!我唯一要做的就是在app / models中重命名modelfile。 (我不得不改变文件名和内容,非常简单!

哦,型号名称与数据库名称不同。 请检查http://rubyonrailsthrissur.wordpress.com/2012/07/18/naming-conventions-while-creating-tables-in-rails/以获取更多命名规则

routes.rb中:

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

journeys_controller(相关部分)

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

new.html.erb(location = journeys / new.html.erb)

<!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>

index.html.erb(location journeys / index.html.erb,这个工作正常)

<!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

我错过了什么吗?

提前致谢!

0 个答案:

没有答案