Both techniques that Ralph mentioned have their place.
Personally I like Responsive Web Design and opt for that first, but it can become complicated.
I'm finding myself swing between these two options and am moving towards having separate views so that you have complete control of the views and can optimise them for mobile. If the use case for the site is different on mobile(people want to do different things) or the site has a certain level of complexity that doesn't make sense on mobile then separate sites with separate views are the right choice.
Very roughly speaking web sites for information should be responsive, web apps that have a lot of user interaction should be separate apps.
Each programming platform on the web(Rails, .NET, PHP etc..) has different options for detecting mobile devices using the userAgent string in the browser.
This list needs to be well maintained to pick up the right devices, so you don't want to roll this sort of thing yourself.
As I work with Rails apps I use the mobile-fu gem which just gives you a helper method is_mobile_device? which you can use in your code to redirect / render different views etc.
Hope it helps,