mercredi 30 septembre 2015

Hashtagging system and autosort

I am stuck with a problem to implement a feature in a photo social app which I am learning to build.

I was wondering of adding a hashtag system to captions. The model scans it, create collections automagically and through a separate controller and display like an album and also have the ability of searching for all photos of all users matching that tags.

I got stuck on the first part of it, scanning for tags and storing it somewhere. I created a new app having post with hashtags and trying to scan through regex - "post.scan(/\B#\w\w+/)".

Thats all I could progress. Coudn't use it anywhere in the controller or model, it keeps saying MoMethod error "scan".

After that how can I store that array somewhere and do rest of the work - which is mostly like a common tagging system.

Model Class name is Photo having attributes - post and hashtag.

def hashtag(post)
hashtag_regex = /\B#\w\w+/
@show = post.scan(hashtag_regex)
end

Controller

def index
@post = Photo.all
@show = Photo.hashtag(@post)
end

Aucun commentaire:

Enregistrer un commentaire