Do controllers in namespaces somehow get their own default layout
file? For instance, the UsersController will use layouts/users.rhtml if it exists. Is there something similar for Admin::UsersController
or will it default to the same file? I tried layouts/
admin_users.rhtml and layouts/admin/users.rhtml with no luck.
admin_articles GET /admin/articles {:action=>"index", :controller=>"admin/articles"}
formatted_admin_articles GET /admin/articles.:format {:action=>"index", :controller=>"admin/articles"}
POST /admin/articles {:action=>"create", :controller=>"admin/articles"}
POST /admin/articles.:format {:action=>"create", :controller=>"admin/articles"}
new_admin_article GET /admin/articles/new {:action=>"new", :controller=>"admin/articles"}
formatted_new_admin_article GET /admin/articles/new.:format {:action=>"new", :controller=>"admin/articles"}
edit_admin_article GET /admin/articles/:id/edit {:action=>"edit", :controller=>"admin/articles"}
formatted_edit_admin_article GET /admin/articles/:id/edit.:format {:action=>"edit", :controller=>"admin/articles"}
admin_article GET /admin/articles/:id {:action=>"show", :controller=>"admin/articles"}
formatted_admin_article GET /admin/articles/:id.:format {:action=>"show", :controller=>"admin/articles"}
PUT /admin/articles/:id {:action=>"update", :controller=>"admin/articles"}
PUT /admin/articles/:id.:format {:action=>"update", :controller=>"admin/articles"}
DELETE /admin/articles/:id {:action=>"destroy", :controller=>"admin/articles"}
]]>[杞琞Why I like Ruby #1: alias_methodhttp://www.aygfsteel.com/martian/archive/2009/04/03/263772.html Martian Martian Fri, 03 Apr 2009 08:18:00 GMThttp://www.aygfsteel.com/martian/archive/2009/04/03/263772.htmlhttp://www.aygfsteel.com/martian/comments/263772.htmlhttp://www.aygfsteel.com/martian/archive/2009/04/03/263772.html#Feedback0http://www.aygfsteel.com/martian/comments/commentRss/263772.htmlhttp://www.aygfsteel.com/martian/services/trackbacks/263772.htmlSo you found yourself in the need to override a method but still count on it’s old behaviour?
No problem! Override it with your new code, call super and…. Uh oh!! Suddenly this turned into a problem… Let me give some more context.
I was testing Ferret (and the acts_as_ferret
plugin) in a project to provide full text search capabilities to our
models. One of the things the plugin does is to add a new method to
ActiveRecord, called find_with_ferret. That way, every model can use it. Great!
So I thought that would make sense for me to remove all diatrictics from the input text before letting ferret do its job. You know, like removing umlauts and all that.
I could do that by overriding this method with code to remove the
undesired chars and then call its older version to finally do the
search - something like calling super, but not quite. And I didn’t want
my models to inherit from anything else than ActiveRecord::Base. That
wouldn’t make any sense.
You know that to redefine a method in an existing class you can open
it up and rewrite it. But since you don’t wanna loose the behaviour
provided by the original method, this is how you can achieve this:
module ActiveRecord class Base
alias_method :find_with_ferret_original, :find_with_ferret
def find_with_ferret(q, options = {}, find_options = {})
remove_diatrictics!(q)
find_with_ferret_original(q, options, find_options)
end
end
end
And you’re good to go. On line 3 you’re just giving the original method an alias, making a copy of it.
Then you redefine it the way you like and on line 6 you call the old version to make sure u still got the same behaviour.
Now all my models can benefit of this change without requiring them to call another method nor inherit from another class.
]]>install ruby on rails, sqlite3, sqlite3-ruby under ubuntu8.10http://www.aygfsteel.com/martian/archive/2009/04/01/263360.html Martian Martian Wed, 01 Apr 2009 06:57:00 GMThttp://www.aygfsteel.com/martian/archive/2009/04/01/263360.htmlhttp://www.aygfsteel.com/martian/comments/263360.htmlhttp://www.aygfsteel.com/martian/archive/2009/04/01/263360.html#Feedback0http://www.aygfsteel.com/martian/comments/commentRss/263360.htmlhttp://www.aygfsteel.com/martian/services/trackbacks/263360.htmlnothing but the script I used:
#install Ruby and relative
apt-get install ruby
#install wget
sudo apt-get install wget
#install rubygems
wget http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz
tar xzf rubygems-1.3.1.tgz
cd rubygems-1.3.1
sudo ruby setup.rb
gem -v
1.3.1
# or update rubygems
sudo gem install rubygems-update -v 1.3.1
#install Rails and dependencies
gem install rails –include-dependencies -v=2.2.2
# [:dependent]
# If set to <tt>:destroy</tt> all the associated objects are destroyed
# alongside this object by calling their +destroy+ method. If set to <tt>:delete_all</tt> all associated
# objects are deleted *without* calling their +destroy+ method. If set to <tt>:nullify</tt> all associated
# objects' foreign keys are set to +NULL+ *without* calling their +save+ callbacks. *Warning:* This option is ignored when also using
# the <tt>:through</tt> option.