Topic: [Share]How to check if current page is Home

As Ruby On Rails developer, someday I need to display an element in home page only. However I don't want to display it on other page. So I need to check if current page is home or not. To check if current page is home or not, I use the following codes

request.path_parameters

The code above will return a hash data type as follow:

{:action => 'current_action', :controller => 'current_controller'}

If the current page is your Rails application homepage, then the hash data type above will be like this one (in almost case including mine).

{:action => 'index', :controller => 'public'}

I suggest you to check it first to make sure which action and controller that serves for your homepage on your Rails application.
Please notice that we can use the request.path_parameters on view. I do it and it solves my problem. After that, you can use it in if-then-else condition as usual.

Source : http://www.kevinhq.com/2012/02/rails-ch … -home.html

Re: [Share]How to check if current page is Home

You just go home page html file and write which element you want to show and where you want.....................................but i don't understand that why u check that page is home or not................................

Re: [Share]How to check if current page is Home

sorry, I misunderstand your question. So please ignore this comment. thank you

Last edited by kevinhq (2012-06-22 09:35:26)

Re: [Share]How to check if current page is Home

but why

Re: [Share]How to check if current page is Home

bharat_soni wrote:

but why

because in my case, I need to display some particular elements in home page only.

and those elements are placed in a partial view , which is used by other pages too

maybe you have better solution ?

I'll be glad to know it.

Last edited by kevinhq (2012-06-22 09:36:30)

Re: [Share]How to check if current page is Home

eddy wrote:

I am very enjoyed for this side. Its a nice topic. It help me very much to solve some problems.

glad to know that, eddy.