Rails3 nomethod error #<ActiveRecord::Relation>
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
.* FROMstaticpages
WHERE (menuname = 'asd')
Couple of working alternatives:
@static = Staticpage.where("menuname = ?", params[:menuname]).first
@static = Staticpage.find_by_menuname(params[:menuname])
精彩评论