开发者

Rails3 nomethod error #<ActiveRecord::Relation>

开发者 https://www.devze.com 2023-02-04 07:50 出处:网络
I\'m writing a static page controller. I get the menuname in the routes.rb and it\'s call the static controller show method.

I'm writing a static page controller.

I get the menuname in the routes.rb and it's call the static controller show method.

match '/:menuname' => 'static#show'

And static_controller.rb:

@static=Staticpage.where("menuname = ?", params[:menuname])

B开发者_StackOverflowut if I want print @static.title in the view, I get this error:

undefined method `title' for #

Whats wrong?

the SQL query looks good:

SELECT staticpages.* FROM staticpages WHERE (menuname = 'asd')


Couple of working alternatives:

@static = Staticpage.where("menuname = ?", params[:menuname]).first
@static = Staticpage.find_by_menuname(params[:menuname])
0

精彩评论

暂无评论...
验证码 换一张
取 消