`
CaiDeHen
  • 浏览: 94282 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论
文章列表
In this third and final episode on complex forms I will show you how to edit a project and multiple tasks all in one form. This includes removing and adding tasks dynamically as well. See the show notes for updated code. <!-- projects/edit.rhtml --> <% form_for :project, :url => project_ ...
See how to use Javascript and RJS to add and remove form fields dynamically. This episode will build upon the previous episode allowing you to create any number of tasks in one form the same time a project is created. <!-- layouts/application.rhtml --> <%= javascript_include_tag :defaults % ...
Complex forms often lead to complex controllers, but that doesn't have to be the case. In this episode see how you can create multiple models through a single form while keeping the controller clean. # projects_controller.rb def new @project = Project.new 3.times { @project.tasks.build } end ...
Rails comes with three environments: development, test, and production. But, you aren't restricted to just these. You can add your own! See how in this episode. # database.yml staging: adapter: mysql database: store_staging user: root password: host: localhost # environments/stagin ...
Controllers are tricky to test, and there's no perfect way to do it. In this episode you will see how I test controllers, and my reasoning behind it. describe MenuItemsController, "creating a new menu item" do integrate_views fixtures :menu_items it "should redirect to ind ...
Do you ever need to generate HTML code in a helper method? Placing it directly in Ruby strings is not very pretty. Learn a great way to generate HTML through Markaby in this episode. def simple_error_messages_for(object_name) object = instance_variable_get("@#{object_name}") return if ...
Ever wonder how to implement OpenID authentication in your Rails app? This episode will show you how to add it to a site with an existing authentication system. # routes.rb map.open_id_complete 'session', :controller => "session", :action => "create", :requirements => { ...
Need multiple user authentication? If so, the restful_authentication plugin is a great way to go. It will generate some basic authentication code for you which is good starting point to your authentication system. Watch this episode for details. script/plugin source http://svn.techno-weenie.net/proje ...
Rake is one of those tools that you don't realize how powerful it is until you start using it. In this episode you will learn how to create custom rake tasks and improve them by using rake features. namespace :pick do desc "Pick a random user as the winner" task :winner => :environ ...
The Railscasts site has been getting a lot of comment spam in the past, but no longer. In this episode I will show you how I solved this problem by using the Akismet web service. # comments_controller.rb def create @comment = Comment.new(params[:comment]) @comment.request = request if @comm ...
By default, Rails uses the model's id in the URL. What if you want to use the name of the model instead? You can change this behavior by overriding the to_param method in the model. Watch this episode for details. # product.rb def to_param "#{id}-#{permalink}" end # controller @pro ...
Have you ever wanted to temporarily disable all validations? Well, ActiveRecord doesn't support this, but that doesn't mean we can't add it. This episode will show you how to open up an existing class and change its behavior. # test_helper.rb class Test::Unit::TestCase self.use_transactional_fixt ...
This is a brief guide to sending email in Rails. See how to configure the environment, generate a mailer, create a template, and deliver the mail. # config/environments/development.rb config.action_mailer.raise_delivery_errors = true # set delivery method to :smtp, :sendmail or :test config.acti ...
Tests which rely heavily on fixtures are brittle and can be difficult to maintain. This episode will show a couple techniques for creating tests which don't use fixtures. # cart_test.rb def test_total_weight_should_be_sum_of_line_item_weights cart = Cart.new cart.line_items.build.stubs(:weight ...
When two people attempt to update the same record near the same time, one of the updates will likely be overwritten. You can solve this problem with optimistic locking. # migrations/011_add_products_lock_version.rb add_column :products, :lock_version, :integer, :default => 0, :null => false ...
Global site tag (gtag.js) - Google Analytics