Basic rule is; If you don’t need to do anything with the relationship model, it may be simpler to set up a has_and_belongs_to_many relationship. You should use has_many :through if you need validations, callbacks, or extra attributes on the join model. For example; Stories can belong to many categories. Categories can have many stories. For [...]
Posts Tagged ‘Ruby on Rails’
has_and_belongs_to_many vs has_many through – Difference between them
Posted in Ruby on Rails, tagged Ruby on Rails on September 24, 2011 | Leave a Comment »
Rails new vs build
Posted in Ruby on Rails, tagged Ruby on Rails on September 23, 2011 | Leave a Comment »
new creates a blank new instance, filling attributes with the passed params. It is only used on a Model class: @post = Post.new(attributes) build is only used on association proxies, not on classes, and it does the same as new, but it also sets the foreign key to the id of the parent element: @comment [...]
[Rails] ActiveRecord::AssociationTypeMismatch Object expected got String error – Solution
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on September 23, 2011 | Leave a Comment »
If you are using select (or similar helpers such as collection_select, select_tag) to set a belongs_to association you must pass the name of the foreign key (in the example below blog_id), not the name of association itself. If you specify blog instead of blog_id Active Record will raise an error along the lines of ActiveRecord::AssociationTypeMismatch: [...]
[Rails] Undefined method `select_tag’ for ActionView::Helpers::FormBuilder on f.select_tag
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on September 23, 2011 | Leave a Comment »
Try; f.select not f.select_tag That should work.
uninitialized constant TwitterAuth::BasicUser::ClassMethods::JSON – [Ruby on Rails]
Posted in installations, Ruby on Rails, Weird Errors, tagged bug fixes, lessons, Ruby on Rails, tips on August 25, 2009 | Leave a Comment »
Got this issue. No worries. Open up environment.rb and Add; config.gem ‘twitter-auth’, :lib => ‘twitter_auth’ That should fix ur issue
Rails UTF-8 problem [utf 8 chars are not showing up properly -Rails 2.3.2 ]
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, Ruby on Rails on August 12, 2009 | Leave a Comment »
Faced this isuue after upgrading to Rails-2. Removing “encoding: utf8″ from database.yml fixed the problem. Don’t know the exact reason. May be included with the rails core?. Suggestions welcome.
load_missing_constant’: uninitialized constant ActionController::AbstractRequest (NameError) [Mongrel - Ruby on Rails]
Posted in installations, Ruby on Rails, Weird Errors, tagged bug fixes, installations, Ruby on Rails on August 5, 2009 | Leave a Comment »
The –prefic option in mongrel configuration causes this error. Go to RAILS_APP/config/mogrel_cluster.yml and remove the “prefix” option If you are having problem in starting the server, without “–prefix” option. Pls refer the workaroung suggested. (http://www.nabble.com/Problem-when-migrating-from-rails-2.2.2-to-rails-2.3.2-on-linux–SLES10-%2B-apache-2-td22961256.html) Copy this file in my_rails_app/config/initializers : abstract_request.rb module ActionController class AbstractRequest < ActionController::Request def self.relative_url_root=(path) ActionController::Base.relative_url_root=(path) end def self.relative_url_root ActionController::Base.relative_url_root [...]
`require_frameworks’: no such file to load — openssl (RuntimeError) [Ruby on Rails]
Posted in installations, Ruby on Rails, Weird Errors, tagged bug fixes, installations, Ruby on Rails on July 28, 2009 | 2 Comments »
If you face an error like this; /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:269:in `require_frameworks’: no such file to load — openssl (RuntimeError) from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/initializer.rb:134:in `process’ Follow these steps: 1. yum install openssl 2. yum install openssl-devel 3. cd /ruby_install_dir/ext/openssl 4. ruby extconf.rb 5. make 6. make install
Rails – Calling multiple redirects or renders fix
Posted in Ruby on Rails, Weird Errors, tagged bug fixes, lessons, Ruby on Rails on July 28, 2009 | Leave a Comment »
Use the “return” statement to fix this issue. (E.g) def do_something redirect_to(:action => “elsewhere”) and return if monkeys.nil? render :action => “overthere” # won’t be called if monkeys is nil end (copied from http://api.rubyonrails.org/classes/ActionController/Base.html)
ERROR RUNNING ‘cluster::configure’: Plugin /cluster::configure does not exist in category /commands [mongrel/Ruby on Rails]
Posted in installations, Ruby on Rails, Weird Errors, tagged bug fixes, installations, lessons, Ruby on Rails on July 22, 2009 | Leave a Comment »
If you see this errror; ERROR RUNNING ‘cluster::configure’: Plugin /cluster::configure does not exist in category /commands Make sure you have; “mongrel_cluster” gem installed. You can see whether it exists in the list by issuing the command; gem list –local If you don’t see it, run; gem install mongrel_cluster That should fix your issue.