ruby on rails - How to create a session out of every time a user uses my webapp? -


to expand on question, have playlist app adds tracks track table whenever create action invoked. every time open instance of localhost:3000, see same set of elements have been added table.

what want every time user opens webapp have own session, fragmenting off of table single user's playlist.

how go doing this? following shows how add elements database in program. if there more information required, let me know.

def create      if is_url(params[:track][:query])            @trackinfo = gettrackinfo(params[:track][:query])     else         @trackinfo = youtubequery(params[:track][:query])      end     @track = track.new(@trackinfo)     @tracks = track.all     @video_ids = track.pluck(:video_id)       if @track.save      else          render :action=>"index"     end end 

i not sure question i'll give try.

you need implement user sign in/sign out. in way each user have own list of tracks. use devise gem. tested , gives need.

you can read more rails session here: http://guides.rubyonrails.org/security.html

hope help.

update

each user comes website gets unique session can use session_id in place of user_id.

super simple solution:

step 1: add column tracks table called user_id (do not forget add index well), session_id string.

step 2: create before_filter in application_controller sets user variable:

class applicationcontroller   before_filter:set_user    # ...    def set_user      @user_id = cookies['_session_id'] # @user_id string   end    # ....  end 

step 3: in create method this

   # ...    # note code give idea     @new_track = track.new(query: @trackinfo)    @new_track.user_id = @user_id     @tracks = track.where(user_id: @user_id)     # .... 

note: more flexible solution requires users table , setting current_user variable based on user_id stored session. see link above.

hope help.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -