<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sean&#039;s Blog &#187; namespace</title>
	<atom:link href="http://seanbehan.com/tag/namespace/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Nesting Resources in Rails Routes.Rb with Namespaces</title>
		<link>http://seanbehan.com/ruby-on-rails/nesting-resources-in-rails-routes-rb-with-namespaces/</link>
		<comments>http://seanbehan.com/ruby-on-rails/nesting-resources-in-rails-routes-rb-with-namespaces/#comments</comments>
		<pubDate>Thu, 08 Apr 2010 15:10:19 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[controllers]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[nested resources]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[routing]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=919</guid>
		<description><![CDATA[When I have a controller that takes more than one has_many argument, I think about creating a namespace. This way I may still use my forums, pages controllers w/out needing any conditional logic, testing for the presence of :course_id in the params hash. #config/routes.rb map.namespace :courses, :path_prefix=&#38;gt;'/courses/:course_id' do &#124;courses&#124; courses.resources :forums courses.resources :pages end map.resources [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fnesting-resources-in-rails-routes-rb-with-namespaces%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Nesting Resources in Rails Routes.Rb with Namespaces" data-url="http://seanbehan.com/ruby-on-rails/nesting-resources-in-rails-routes-rb-with-namespaces/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>When I have a controller that takes more than one has_many argument, I think about creating a namespace. This way I may still use my forums, pages controllers w/out needing any conditional logic, testing for the presence of :course_id in the params hash.</p>
<pre class="wp-code-highlight prettyprint">
#config/routes.rb
map.namespace :courses, :path_prefix=&amp;gt;'/courses/:course_id' do |courses|
  courses.resources :forums
  courses.resources :pages
end

map.resources :courses
map.resources :forums
map.resources :pages
</pre>
<pre class="wp-code-highlight prettyprint">
# some view.html.erb
&amp;lt;%= courses_forums_path(1) %&amp;gt; /courses/1/forums
&amp;lt;%= courses_pages_path(2) %&amp;gt; /courses/2/pages
# w/ use in a form don't forget to pass an array instead of just the resource (will map to forums_controller)
&amp;lt;%=form_for [:courses, Forum.new] do |f| %&amp;gt;&amp;lt;%end%&amp;gt;
</pre>
<p>in the namespaced controller you can extend the parent controller (if you like) to have access to methods coursescontroller defines.</p>
<pre class="wp-code-highlight prettyprint">
# app/controllers/courses/forums_controller.rb
class Courses::ForumsController &amp;lt; CoursesController
 before_filter :require_course_login #defined in parent ../courses_controller.rb
 def index
  end
end
</pre>
<p>to use the generator to create namespaced controller</p>
<pre class="wp-code-highlight prettyprint">./script/generate controller 'courses/forums' </pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/nesting-resources-in-rails-routes-rb-with-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Namespacing in Rails</title>
		<link>http://seanbehan.com/ruby-on-rails/namespacing-in-rails/</link>
		<comments>http://seanbehan.com/ruby-on-rails/namespacing-in-rails/#comments</comments>
		<pubDate>Fri, 27 Mar 2009 19:36:50 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[namespace]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[routes]]></category>

		<guid isPermaLink="false">http://bseanvt.wordpress.com/?p=85</guid>
		<description><![CDATA[With namespace routes in Rails you can easily create a prefix for select resources. For instance, if you have an admin area or an account dashboard you can give logged in users access to methods that are not otherwise available. To use namespaces define them in config/routes.rb. *Note: this is available for the latest release [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fnamespacing-in-rails%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Namespacing in Rails" data-url="http://seanbehan.com/ruby-on-rails/namespacing-in-rails/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>With namespace routes in Rails you can easily create a prefix for select resources. For instance, if you have an admin area or an account dashboard you can give logged in users access to methods that are not otherwise available. To use namespaces define them in config/routes.rb. *Note: this is available for the latest release of Rails, at this time it is 2.3.0. I think it&#8217;s supported back until Rails 2.0, but haven&#8217;t tested it.</p>
<p>In your config/routes.rb file</p>
<pre class="wp-code-highlight prettyprint">map.namespace :dashboard do |dashboard|
    dashboard.resources :properties, :collection=&amp;gt;{:available =&amp;gt; :get}
end</pre>
<p>This namespace will create routes such as dashboard/properties, dashboard/properties/1, essentially all the CRUD paths as well as a collection method &#8220;available&#8221; dashboard/properties/available. These routes can be accessed in your views with methods such as new_dashboard_property_path, available_dashboard_properties_path  etc. If your property model has it&#8217;s own controller that isn&#8217;t namespaced, properties_controller.rb, remember to modify the property form_for method to tell it to use the dashboard namespace. The normal form_for(@property), method takes just your property object. Instead pass the dashboard symbol inside of an array  to form_for</p>
<pre class="wp-code-highlight prettyprint">&amp;lt;% form_for [:dashboard, @property] do |f| %&amp;gt;&amp;lt;% end %&amp;gt;</pre>
<p>You can easily see all of the available paths from the command line using rake routes. I use grep to filter the results for conveinence, because on a large application I don&#8217;t necessarily need to see all the routes if I&#8217;m working just within a single namespace. rake routes | grep dashboard</p>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/namespacing-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

