2012-05-05 234 views
0
def tag_autocomplete 
     @tags = Tag.find_by_sql("SELECT tag_name as id,tag_name as label,tag_name as value FROM tags ") 
     render :json => @tags.to_json 
    end 

渲染JSON不工作我收到以下錯誤渲染JSON錯誤

ArgumentError (wrong number of arguments (0 for 2)): 
    /app/controllers/tags_controller.rb:32:in `to_json' 

我使用Ruby 1.8.6和軌道提前

+0

你的標籤模塊是怎樣的? –

+0

你是否有機會重寫'Tag'模型中的'to_json'方法? – rubyprince

回答

0

檢查2.3.5

謝謝如果這有幫助

format.json { render json: @tags } 

編輯

它可能是sql語句或類成員的命名。你可以發佈你的Tag類嗎?

試試這個。如果它有效,它意味着類和變量名稱不匹配數據庫列。您可以在模塊\類中修復它以指示列名。

@tags = Tag.all 
render :json => @tags 
+0

感謝您的回覆。我已經嘗試過這一個也是相同的錯誤 –

0

其實,你不需要to_json。 render:json => @tags 就足夠了

+0

我已經嘗試過,但也是同樣的錯誤 –