コントローラーとモデルの名前が違っても良いのでしょうか?
例えば、以下のようにHelloControllerの中にPostモデルから、情報を取って来るコードを書いたとします
controller
1class HelloController < ApplicationController 2 def index 3 @posts = Post.all.order("id DESC") 4 end 5 6 def edit 7 @post = Post.find(params[:id]) 8 end 9 . 10 . 11 12end
route
1 resources :hello, :only => :edit 2 get "/hello/index" => "hello#index"
index
1<% @posts.each do |post| %> 2 <div> 3 <p>id:<%= post.id %></p> 4 <%= link_to "編集", edit_hello_path(post) %> 5 6 </div> 7<% end %> 8</body>
edit
1<%= @post.id %>
「require 'byebug'; byebug」でデバックしても、indexアクションは通っているようなのですが、editアクションはとおっていません。
rails cで確認すると、Postのid=1はあり、
idnex(Post.all.order)は表示されますが、
「/hello/1/edit」で表示されません、
「undefined method `id' for nil:NilClass」のエラーが出てしまいます。
これはコントローラーとモデルの名前が違うからでしょうか?
それとも、名前が違っても表示されますか?