- 浏览: 94282 次
- 性别:
- 来自: 成都
最新评论
-
xylffxyfpp:
应该改成慎用each
万恶的"delete",慎用数组的delete -
xylffxyfpp:
a = [1,2,3,4,5,6]
a.each do ...
万恶的"delete",慎用数组的delete -
CaiDeHen:
受教了,我也不知道当时为什么会在这个地方这样子用。其他地方也是 ...
万恶的"delete",慎用数组的delete -
wosmvp:
感觉太乱了为什么不在User模型中来个 named_scope ...
万恶的"delete",慎用数组的delete -
jiachengxi38:
不知道楼主这样的逻辑想法从何而来,权限访问的思想好像在lZ这里 ...
万恶的"delete",慎用数组的delete
文章列表
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_ ...
- 2008-12-09 19:56
- 浏览 876
- 评论(0)
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 % ...
- 2008-12-05 17:12
- 浏览 697
- 评论(0)
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
...
- 2008-12-05 17:04
- 浏览 702
- 评论(0)
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 ...
- 2008-12-05 16:58
- 浏览 585
- 评论(0)
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 ...
- 2008-12-05 15:24
- 浏览 648
- 评论(0)
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 ...
- 2008-12-05 11:17
- 浏览 649
- 评论(0)
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 => { ...
- 2008-12-05 10:56
- 浏览 742
- 评论(0)
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 ...
- 2008-12-05 10:54
- 浏览 770
- 评论(0)
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 ...
- 2008-12-05 10:50
- 浏览 680
- 评论(0)
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 ...
- 2008-12-05 10:26
- 浏览 637
- 评论(0)
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 ...
- 2008-12-05 10:21
- 浏览 759
- 评论(0)
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 ...
- 2008-12-05 10:17
- 浏览 678
- 评论(0)
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 ...
- 2008-12-05 10:14
- 浏览 662
- 评论(0)
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 ...
- 2008-12-05 10:11
- 浏览 677
- 评论(0)
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
...
- 2008-12-05 09:45
- 浏览 654
- 评论(0)