Conditional root_url (index)

I want my application to display different data on the main page depending on whether the user has been registered or not.

def index

  if current_user
    # render another controllers action
  else
    # render another controllers action
  end

end

I can achieve this using render_component. However, it has been deprecated for some time. Although I can still use it as a plugin, I am wondering if anyone has a better approach. Just keep in mind that rendering a different kind of controller directly is not an option.

Thank.

+3
source share
2 answers

Just use your method indexas a public proxy for the specific view you want to display.

def index
  if user?
    logged_in
  else
    logged_out
  end
end

private

def logged_in
  # stuff
  render :action => "logged_in"
end

def logged_out
  # stuff
  render :action => "logged_out"
end    
+3
source

, , , .

+1

Source: https://habr.com/ru/post/1731467/


All Articles