Rails: Passing params from URL to view without looking up the database -


i have url example.com/test/this_text. now, when user comes url, want use "this_text" part inside routed html.erb view as-is.

i know wouldn't mvc anymore, trying avoid overhead making process independent model , database. there simple way directly pass url params view in rails?

update:

some code:

routes.rb

get "/d/:token", to: "games#show" 

games_controller.rb

class gamescontroller < applicationcontroller     before_action :set_game, only: [ :edit, :update, :destroy]      def show         @text = params["token"]     end     #other scaffold stuff... end 

show.html.erb

your entered text <%= @text %> 

error

actioncontroller::parametermissing in gamescontroller#show

param missing or value empty

how declaring this_text in routes.rb file?

if if declared

get '/test/:this_text' (note :)

then can access params[:this_text] in controller.

so:

# in routes.rb   '/test/:test_text', to: 'tests#show_text'  # in tests_controller.rb  class testscontroller < applicationcontroller    def show_text     @text = params[:test_text]   end end 

hope helps!


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -