简体   繁体   中英

render json error

   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

render json not working I am getting the following error

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

I am using ruby 1.8.6 and rails 2.3.5

Thanks in Advance

Check if this helps

format.json { render json: @tags }

Edit

It might be the sql statement or the class members naming. Could you post your Tag class, please.

Try this. If it works it means the class and variable names do not match the db columns. You can fix that at the module\\class to indicate the column name.

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

Actually, You do not need to_json. render :json => @tags will be enough

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM