Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Thorstein Nordby
17,115 PointsMaking a landing page for RoR application
Hi!
I am making a web app with RoR, and I can't figure out this seemingly simple problem.
I want to create a welcome page, much like the one you see when you are logged out of www.teamtreehouse.com. It is a site where you can log in, see pricing etc. When a user log in, I want them to be redirected to a dashboard, similar to the one we use here.
I can't figure out how to get the code separate from my landing page and application.html.erb code. Now they just mix. How do I make the application and welcome page separate?
5 Answers
Geoff Parsons
11,679 PointsFirst you'll need a route that points the root URL to a specific controller action (http://example.com/ as an example).
root :to => 'welcome#index'
In this case we point it to the index action of the welcome controller, but it can be anywhere you wish.
I'll assuming you're using Devise for authentication; in order to redirect users to a dashboard after signing in you can define "after_sign_in_path" in your ApplicationController like so:
def after_sign_in_path_for(user)
dashboard_path
end
In this method you could even inspect the user and send different types of users to different dashboards for instance.
Hope this helps!
Thorstein Nordby
17,115 PointsWOW thank you so much! Appreciate it :)
Jamie Barton
14,498 Pointsroot "welcome#index" also works just fine in Rails 4.
Thorstein Nordby
17,115 PointsOk, to expand a bit on this problem:
I have a "welcome.html.erb" file, and I have a "dashboard.erb.html" file. I have created a user model with devise so that new users can sign up.
I want new users to see the welcome page when they are not signed in. When they do create a account, I want them to be redirected to "dashboard.erb.html". Geoff covered this pretty well, but.....!
What I can't figure out is how I can get my code written in "welcome.html.erb" to override the code I have written in "application.scss" and "application.html.erb". Right now the two layouts just mix of dashboard and welcome. I want the welcome "index.html.erb" to be a static html page without ANY of the code written in the application files.
I have tried playing around with RENDER in the welcome controller, but no success. I either get a functioning, but blank page, or a mix of both "application.html.erb" and "dashboard.html.erb".
Any suggestions on how to fix this? Thanks!
Adam Sackfield
Courses Plus Student 19,663 PointsI am working through this rails tutorial and the chapter I linked is all about sign-in/out sessions and rendering different content depending on signed in or not. Believe this is what you need to look into. Thorstein Nordby
Thorstein Nordby
17,115 PointsAhhh finally.
I just had to add...
render :layout => false
... to my controller. Thanks for the tutorial Adam Sackfield. Really helpful tutorial ;)
Adam Sackfield
Courses Plus Student 19,663 PointsBest one I have seen, for detail!
Adam Sackfield
Courses Plus Student 19,663 PointsAdam Sackfield
Courses Plus Student 19,663 PointsThis is something that is covered in the Treebook courses on here. I don't remember the specifics of how it was implemented but I am sure if you look through courses for Treebook you will stumble across it :)