开发者

Rails3 nomethod error #<ActiveRecord::Relation>

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜