Eleeist
Eleeist

Reputation: 7041

Rails private views and controllers

Is it possible to create a private view and controller, so that I can only invoke it somehow from the code?

I would like to be able to display dynamic widgets in different parts of my application. I thought about creating a controller and view for them and then rendering them in places I want, however then people will be able to see them just typing the correct URL.

Or maybe I could prevent that with some rule in routes.rb?

Upvotes: 0

Views: 80

Answers (2)

Enrique Galindo
Enrique Galindo

Reputation: 221

I think that your problem will be solved using partial views, you need to create each widget like a partial view and call each partial in the view that you want to have widgets.

Also you may need to have the variables loaded like a normal view.

Upvotes: 1

Sagiv Ofek
Sagiv Ofek

Reputation: 25280

you can put filtters in your controller for specific actions. that way only people with specific permissions (admins?) can access it:

before_filter :require_login

private     
def require_login
    unless logged_in?
      flash[:error] = "You must be logged in to access this section"
      redirect_to new_login_url # halts request cycle
    end
end

Upvotes: 0

Related Questions