Here are some great posts about rails development, hosting, hiring, etc:
Ruby on Rails Hosting
An overview of some Ruby on Rails development and hosting companies.
View more »
11 Tips on Hiring a Rails Developer
Tips include looking for people who have contributed to the community, and more.View more »
Hosting Rails
A very cheap hosting company that offers mongrel for as little as $10 per month.View more »
Thursday, August 7, 2008
Friday, August 1, 2008
Custom 404 Pages - Rails 404 Status
Sometimes your application hits it where it doesn't know what to render. Perhaps your user tried to access so URL from memory and spelled it wrong. Maybe they tried /user/john instead of /users/john. Whatever happens, they'll be getting some sort of error. Fortunately for you, you can control this error without much work. Add this to the bottom of your routes.rb file.
map.connect '*path', :controller => 'application', :action => 'rescue_404' unless ::ActionController::Base.consider_all_requests_local
Then add to your application.rb
Sometimes you may want to throw a 404 yourself. For example if they go to /wiki/doesnotexist you can render your own page. Use something as simple as:
render :action => "something", :status => 404
or as simple as
render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 and return
map.connect '*path', :controller => 'application', :action => 'rescue_404' unless ::ActionController::Base.consider_all_requests_local
Then add to your application.rb
def rescue_404
rescue_action_in_public CustomNotFoundError.new
end
def rescue_action_in_public(exception)
case exception
when CustomNotFoundError, ::ActionController::UnknownAction then
#render_with_layout "shared/error404", 404, "standard"
render :template => "shared/error404", :layout => "standard", :status => "404"
else
@message = exception
render :template => "shared/error", :layout => "standard", :status => "500"
end
end
def local_request?
return false
end
Sometimes you may want to throw a 404 yourself. For example if they go to /wiki/doesnotexist you can render your own page. Use something as simple as:
render :action => "something", :status => 404
or as simple as
render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 and return
Monday, June 2, 2008
Scaffold versus Scaffold Resource
Scaffolding has always been the standard way to start a Ruby on Rails piece/component/controller, generating the standard files and paths based on the specified model name. More recently, though, scaffold now creates a RESTful version of these rails conventions. At one time it simply generated regular CRUD, and then scaffold_resource came along to create a REST-based controller, model, and views. Now scaffold does that, by creating the correct views, actions, and allowing Rails to respond to different types of requests (XML, HTML, etc), which make it more restful.
Thursday, May 15, 2008
Give it a REST
So recently I learned what REST really meant. Basically it's CRUD+. This means you have Create, Read, Update, Delete, and then add in Index, Edit, & New. For some reason this is a big deal... I just thought that was a regular ol rails feature. But rest also involves using a resources map to do things like this:
map.resources :newsstory
Which then gives you access to things like
new_newsstory_path
edit_newsstory_path(@newsstory)
REST Examples
You get all this after map.resources :object
Path for the form to create a new object -> new_object_path
Path to create new object -> object_path (:method => :post)
Path to edit object -> edit_object_path(@object)
Path to send the edit form (update object) -> object_path(@object) (:method => :put)
Path to view object -> object_path(@object)
map.resources :newsstory
Which then gives you access to things like
new_newsstory_path
edit_newsstory_path(@newsstory)
REST Examples
You get all this after map.resources :object
Path for the form to create a new object -> new_object_path
Path to create new object -> object_path (:method => :post)
Path to edit object -> edit_object_path(@object)
Path to send the edit form (update object) -> object_path(@object) (:method => :put)
Path to view object -> object_path(@object)
Subscribe to:
Posts (Atom)
