1. do find => rescue
2. model operation more than 3 lines => define class method in model
3. def current_user
4. render_as_form
5. more than one relation in one table
6. composite primary key => hook
Showing posts with label rails. Show all posts
Showing posts with label rails. Show all posts
Tuesday, April 28, 2009
Wednesday, March 25, 2009
Rails on FreeBSD 7.1
Today I was first time trying to install rails on freebsd 7.1. Neither the ports version nor the gem file version, rails could not work, even only simply creating a new project. It returns message as following.
I had try to reinstall ruby, rubygem, and try other version rails but a nonsense. And finally I forgot how did I discover it needs ruby-iconv ports in fact. It seems occurring at the time I was using rails 2.2.2, some keyword appeared in the error message.
One post on the mailing list [Ruby on Rails : Talk] show the same problem. If you also have the same problem, try it.
undefined method `camelize' for "app":String
I had try to reinstall ruby, rubygem, and try other version rails but a nonsense. And finally I forgot how did I discover it needs ruby-iconv ports in fact. It seems occurring at the time I was using rails 2.2.2, some keyword appeared in the error message.
One post on the mailing list [Ruby on Rails : Talk] show the same problem. If you also have the same problem, try it.
Saturday, July 12, 2008
Tuesday, June 3, 2008
operate existed tables in rails
Just need specify table name and primary key in Model. All attribution in tables will appear automatically.
class ModelName < ActiveRecord::Base
self.table_name = "table_name"
self.primary_key = "primary_key"
end
Labels:
programming,
rails,
ruby
Saturday, April 19, 2008
has_many() function note
if has_many :order
order.delete_all just set foreign key null
order.destroy_all clear all sub record
order.delete_all just set foreign key null
order.destroy_all clear all sub record
Labels:
programming,
rails,
ruby
Friday, April 18, 2008
apache2 and mongrel cluster on debian
Enable apache2 proxy
Configure Proxy in a virtual host
/etc/apache2/site-enabled/default add
Then set mongrel cluster
Final, restart apache2 and it work.
$ sudo a2enmod proxy proxy_http proxy_balancerConfigure Proxy in a virtual host
/etc/apache2/site-enabled/default add
DocumentRoot "RailsApp/public"
# even only RailsApp also work
ProxyPass / balancer://localhost/
ProxyPassReverse / balancer://localhost/
< proxy balancer://localhost/ >
BalanceMember http://localhost:3000
BalanceMember http://localhost:3001
BalanceMember http://localhost:3002
< /proxy >Then set mongrel cluster
$ sudo gem install mongrel_cluster
$ cd RailsApp
$ mongrel_rails cluster::configure -e development -p 3000 -N 3
# write config/mongrel_cluster.yml
$ mongrel_rails cluster::startFinal, restart apache2 and it work.
Labels:
deploy,
rails,
ruby,
webservice
Thursday, April 17, 2008
rss feed in rails
Note for the Way to create Atom and RSS 2.0 feed.
Suppose that the model we want show in feed is Post
Then write the view.
app/view/feed/rss.rxml
app/view/feed/atom.rxml
app/view/layout/application.rhtml add
$ ./script/generate controller feedSuppose that the model we want show in feed is Post
class FeedController < ApplicationController
def rss
@rss = @@post
end
def atom
@atom = @@post
end
private
@@post = Post.find :all,
:order => "update_at", :limit => 10
endThen write the view.
app/view/feed/rss.rxml
01 xml.instruct! :xml, :version=>"1.0"
02 xml.rss(:version=>"2.0"){
03 xml.channel{
04 xml.title("The site title")
05 xml.link(url_for("/"))
06 xml.description("The site description")
07 xml.language('en-us')
08
09 @rss.each do |rss|
10 xml.item {
11 xml.title rss.title
12 xml.link ""
13 xml.description rss.content
14 xml.pubDate rss.update_at
15 xml.guid ""
16 xml.author rss.declarer
17 }
18 end
19 }
20 }app/view/feed/atom.rxml
01 xml.instruct! :xml, :version=>"1.0"
02 xml.feed "xmlns" => "http://www.w3.org/2005/Atom" do
03 xml.title("The site title")
04 xml.link(url_for "/")
05 @atom.each do |atom|
06 xml.entry {
07 xml.title(atom.title)
08 xml.summary(atom.content)
09 }
10 end
11 endapp/view/layout/application.rhtml add
<%= auto_discovery_link_tag :rss, { :controller => '/rss', :action => 'rss' }, { :title => "RSS 2.0" } %>
<%= auto_discovery_link_tag :rss, { :controller => '/rss', :action => 'atom' }, { :title => "Atom" } %>
Labels:
programming,
rails,
ruby
Tuesday, April 15, 2008
rails helper block
Write for memo.
To set a helper in the form
<% helper_name do %>
<div>blah</div>
<% end %>.
The definition is
By the way, partial is the way do the same thing once. if the outer html is used frequently, the way to define a helper as above will be better.
To set a helper in the form
<% helper_name do %>
<div>blah</div>
<% end %>.
The definition is
def helper_name(&block)
content = capture(&block)
concat("what we want write before block".block.binding)
concat(content,block.binding)
concat("what we want write after block",block.binding)
endBy the way, partial is the way do the same thing once. if the outer html is used frequently, the way to define a helper as above will be better.
Labels:
programming,
rails,
ruby
Sunday, April 13, 2008
spakit
The rails plugin spakit means Single Page Application KIT. It can transform rails app into single page app but not modify app structure in large scale by loading content of other controller into primary controller.
The installation step is from handlino.com
now installation finished.
Before using it, spakit need a layout railsapp/app/view/layout/spakit.rhtml
And the layout application.rhtml should contain
<%= javascript_include_tag :defaults %> to include default js file.
Now we can use it happy. Add <div id="content"></div> into the view of primary controller, and set a spakit link: <%= spakit_link_to 'new person', :url => new_person_path %>, the content of the url will appear in the div#content.
Also two other helpers contain in spakit, spakit_form_for and spakit_form_tag
link1: spakit at rubyforge
link2: spakit at github
The installation step is from handlino.com
$ sudo gem install spakit
$ cd railsapp/vendor/plugins/
$ gem unpack spakit
$ mv spakit-version spakitnow installation finished.
Before using it, spakit need a layout railsapp/app/view/layout/spakit.rhtml
<%= flash[:notice] %>
<%= yield %>And the layout application.rhtml should contain
<%= javascript_include_tag :defaults %> to include default js file.
Now we can use it happy. Add <div id="content"></div> into the view of primary controller, and set a spakit link: <%= spakit_link_to 'new person', :url => new_person_path %>, the content of the url will appear in the div#content.
Also two other helpers contain in spakit, spakit_form_for and spakit_form_tag
link1: spakit at rubyforge
link2: spakit at github
annotate models
The plugin used for adding column annotate into model file is introduced in Ralls Bible. Write for note. the newer introduction at http://pragdave.pragprog.com/pragdave/2006/02/annotate_models.html. Just two step to use it.
1.script/plugin install http://repo.pragprog.com/svn/Public/plugins/annotate_models
2. rake annotate_models
And all model now with column annotate at file head.
1.script/plugin install http://repo.pragprog.com/svn/Public/plugins/annotate_models
2. rake annotate_models
And all model now with column annotate at file head.
Subscribe to:
Posts (Atom)