ruby on rails - Routing the URL using values from database? -


i have controller streams_controller , model streams.

class streamscontroller < applicationcontroller   def new     @stream = stream.new   end    def create     @stream = stream.new(params[:stream])     if @stream.save         flash[:success] = "welcome!"         redirect_to @stream     else         render 'new'     end   end     def show     @stream = stream.find(params[:id])   end end 

and

class stream < activerecord::base     attr_accessible :name, :email, :password, :password_confirmation     before_save { |stream| stream.name = name.downcase }      has_secure_password . . . 

basically work show method, have go localhost/streams/[id] [id] id of particular stream. possible reroute url go this: localhost/[name] [name] :name attribute of stream model?

so new url created every time new stream created, , correspond name of stream in database.

how go implementing this?

anyways, or thoughts appreciated!

i make streams part of url short possible, not empty (to avoid collisions in case of using names instead of ids).

resources :streams, path: 's' 

url /s/stream-a isn't big compromise.

about using name instead of id in url see this railscast.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

java - stack overflow exception on xml transformation -