ruby on rails - how to append unique string at the end of resource routes in rails4 -


i tried rails guide , searched lot can find answer. trying generate secret post scaffold in rails 4 using scaffold generator

scenario : users can create secret posts , link secret token in future works verification string

rails g scaffold secret title:string content:text token:string

i want append token value in "secret_posts" routes

eg:

: secret/1/sadkljaldjlak   : secret/1/edit/sasadadallkha 


i want use token unique code verification . appreciated

first, create migration chance token:string token:text, use secureramdom.urlsafe_base64 generate token, use code on model:

def secret_token    if self.new_record?      self.token = securerandom.urlsafe_base64    end end 

after that, create route this:

get   'secret/:edit_hash/edit',        to: 'secret#edit', as: :secret_offer patch 'secret/:edit_hash',             to: 'secret#update' put   'secret/:edit_hash',             to: 'secret#update' 

and on controller:

def edit   @secret = secret.find_by!(edit_hash: params[:edit_hash])   code.. end  def create   @secret = secret.find_by!(edit_hash: params[:edit_hash])   code.. end 

hope help


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -