Screencast: Subdomains in Rails 3
Seit Rails 3 ist es nun möglich Subdomains ohne zusätzliche Plugins zu benutzen bzw. einzusetzen. Ryan zeigt diese Woche wie.
Download:
Download(18.8 MB, 13:55)
Alternativer Download für iPod & Apple TV(18.5 MB, 13:55)
Resourcen:
Quellcode:
# routes.rb
constraints(Subdomain) do
match '/' => 'blogs#show'
end
# lib/subdomain.rb
class Subdomain
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www"
end
end
# app/helpers/url_helper.rb
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
end
# application_controller.rb
include UrlHelper
# config/initializers/session_store.rb
# requires Rails 3.0 RC or head
Rails.application.config.session_store :cookie_store, :key => '_blogs_session', :domain => :all
# change top level domain size
request.domain(2)
request.subdomain(2)
Rails.application.config.session_store :cookie_store, :key => '_blogs_session', :domain => "example.co.uk"
<!-- blogs/index.html.erb --> <%= link_to blog.name, root_url(:subdomain => blog.subdomain) %> <!-- blogs/show.html.erb --> <%= link_to "All Blogs", root_url(:subdomain => false) %>
Eingestellt am 05.07.2010 um 14:34
Kategorie: Tutorials
Suchen auf rubyonrails.de
Tags
2.0 Action Active-Record ActiveRecord Ajax Buch Capistrano Enterprise Event Formulare Gewinnspiel Grundlagen IDE irb jQuery Kochbuch Konferenz Mac OpenRoRBook OReilly OSX Passenger Phusion Plugin PragProgs Rails Rails 3 RailsWayCon Release Release Candidate Routing Ruby Ruby 1.9 RubyGems rubyonrails.de Ryan Bates Scaffolding Screencast Script-Tip Security Tutorial Upgrade Video Views WindowsAktuelle Artikel
- Scripttip: Herausfinden ob ein Datum in einen bestimmen Zeitraum fällt
- Scripttip: Herausfinden ob ein Wert numerisch ist
- Screencast: Resourcen vererben
- Ruby on Rails 2.3.9 veröffentlicht
- Alle Links zu Rails 3
- Rails 3 Upgrade Handbook PDF
- Ruby on Rails 3: Moderne Webentwicklung mit Ruby
- Rails 3.0 ist fertig
- Screencast: Polling nach Aktualisierungen
- Screencast: Sortierbare Tabellen
Artikel Archiv
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- August 2008
- July 2008
- June 2008
- May 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
Aktuelle Rails Version + Abhängigkeiten:
Gem rails-3.0.0actionmailer (= 3.0.0, runtime)
actionpack (= 3.0.0, runtime)
activerecord (= 3.0.0, runtime)
activeresource (= 3.0.0, runtime)
activesupport (= 3.0.0, runtime)
bundler (~> 1.0.0, runtime)
railties (= 3.0.0, runtime)
Rails auf Rubyforge
Rails auf Github