惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
GbyAI
GbyAI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
Recent Announcements
Recent Announcements
L
LangChain Blog
B
Blog
阮一峰的网络日志
阮一峰的网络日志
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
M
MIT News - Artificial intelligence
D
Docker
WordPress大学
WordPress大学
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The GitHub Blog
The GitHub Blog
博客园 - 叶小钗
Last Week in AI
Last Week in AI
Stack Overflow Blog
Stack Overflow Blog
有赞技术团队
有赞技术团队
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MongoDB | Blog
MongoDB | Blog
博客园 - Franky

Ruby on Rails: Compress the complexity of modern web apps

Safer to_i coercion, custom to_fs formats, and more! This Week in Rails: May 16, 2026 This Week in Rails: May 8, 2026 This Week in Rails: May 1, 2026 Active Record gets better every week Great big Rails World 2026 update: CFP, Corporate Support tickets, workshops Query command for database queries and more Explicit query: and body: kwargs for integration tests and more! Speedup ActiveRecord::LogSubscriber#sql_color and more! This Week in Rails: March 27, 2026 Rails Versions 8.0.5 and 8.1.3 have been released! Rails Versions 7.2.3.1, 8.0.4.1, and 8.1.2.1 have been released! This Week in Rails: March 20, 2026 Validate URI scheme in Action Text and more This Week in Rails: March 6, 2026 Planning Center is the newest Rails Foundation Contributing member Action Text gets Markdown conversion, editor links in devcontainers, and more! BARRA seeks Rails developer Joe Agliozzo is looking for a Rails developer The rise of lighttpd as the alternative web server When longer is better and more is more Snowdevil: First e-tailer on Rails Natural selection for frameworks in Ruby vs Java Address book tutorial in Portuguese Becoming a better programmer with Rails 10 Things Every Java Programmer Should Know About Ruby Really Getting Started in Rails Off the Treadmill, Onto the Rails Rails 0.9.5: A world of fixes and tweaks Rich clients with Rails and XUL
Rails 1.2 RC1: New in Action Pack
David Heinemeier Hansson · 2006-11-26 · via Ruby on Rails: Compress the complexity of modern web apps

Sunday, November 26, 2006
Posted by josh

With all respect to the reporter from the Edge, here are a few tasty bits from ActionPack in Rails 1.2 (CHANGELOG). (compiled by Geoffrey Grosenbach).

<h1>Views</h1>


<p>You can now access nested attributes in <span class="caps">RJS</span>:</p>


<pre><code>page['foo']['style']['color'] = 'red' # =&gt; $('foo').style.color = 'red';</code></pre>


<p>Forms now use blocks instead of <code>end_form_tag</code> (<a href="http://www.loudthinking.com/arc/000601.html">notes from <span class="caps">DHH</span></a>):</p>

<% form_tag(products_url) do %>
  <%= text_field :product, :title %>
  <%= submit_tag "Save" %>
<% end -%>
<p>And how many blogs have you visited that say &#8220;Last updated 60 days ago&#8221;? Years and months have been added to <code>distance_of_time_in_words</code>, so you&#8217;ll see &#8220;2 months ago&#8221; or maybe even &#8220;5 years ago&#8221; now.</p>


<h1>Controllers</h1>


<p>Uncaught exceptions raised anywhere in your application will cause <code>RAILS_ROOT/public/500.html</code> to be read and shown instead of just the static &#8220;Application error (Rails).&#8221; So make it look nice if you aren&#8217;t using it already!</p>


<p>There is a new <code>head(options = {})</code> method for responses that have no body.</p>


<pre><code>head :status =&gt; 404 # return an empty response with a 404 status head :location =&gt; person_path(@person), :status =&gt; 201</code></pre>


<p>You can declare specific file extensions exempt from layouts. Bring on the <span class="caps">CSS</span>, PDF, and graphic generating plugins!</p>


<pre><code>ActionController::Base.exempt_from_layout 'rpdf'</code></pre>


<p>RESTful resources automatically get a <code>params[:format]</code> option that can force a content type. If :format is specified and matches a declared extension, that mime type will be used in preference to the &#8220;Accept&#8221; header. This means you can link to the same action from different extensions and use that fact to determine output (<a href="http://nubyonrails.com/articles/2006/10/09/peepcode-rest-basics">cheat sheet</a>).</p>


<pre><code>class WeblogController &lt; ActionController::Base   def index
@posts = Post.find :all
respond_to do |format|
  format.html
  format.xml { render :xml =&gt; @posts.to_xml }
  format.rss { render :action =&gt; "feed.rxml" }
end   end</code></pre>


<p>You can also register your own custom <span class="caps">MIME</span> types. These will be automatically incorporated into controllers so you can use them in <code>respond_to</code> blocks and as file <code>:format</code> extensions.</p>


<pre><code>Mime::Type.register(string, symbol, synonyms = []) Mime::Type.register("image/gif", :gif)</code></pre>


<p>Finally, <code>ActionController.filter_parameter_logging</code> makes it easy to remove passwords, credit card numbers, and other sensitive information from being logged when a request is handled.</p>


<pre><code>filter_parameter_logging 'password' # Don't log fields that match 'password'</code></pre>


<h1>Routing and URLs</h1>


<p>Routing has been significantly rewritten for speed and consistency. One of the benefits is that you can use named routes and RESTful routes in your mailer templates.</p>

class MyMailer < ActionMailer::Base

  include ActionController::UrlWriter
  default_url_options[:host] = 'my_site.com'
<h1>Testing</h1>

assert_response now supports additional symbolic status codes.


  assert_response :success # You know this one
  assert_response :ok
  assert_response :not_found
  assert_response :forbidden
<p>Added the rulin&#8217; <code>assert_select</code> for <span class="caps">CSS</span> selector-based testing (<a href="http://blog.labnotes.org/2006/09/04/assert_select-cheat-sheet/">cheat sheet</a>). Use this instead of <code>assert_tag</code> from now on. </p>


<pre><code>assert_select "a[href=http://assert_select_rules.com]", @item.url, "Should have a link"  assert_select "div#products", nil, "Should show a products div on the page"</code></pre>


<h1>Deprecated</h1>


<p>You&#8217;ll see warnings when you run your test suite. Here are a few that have been replaced with better syntax:</p>


<ul>
<li>assert_tag &rarr; assert_select</li>
</ul>


<ul>
<li>start_form_tag and end_form_tag &rarr; form_tag do end</li>
</ul>


<ul>
<li>@cookies, @headers, @request, @response, @params, @session, @flash &rarr; cookies, headers, request, response, params, session, flash</li>
</ul>


<ul>
<li>.png is no longer automatically appended to extension-less <code>image_tag</code> calls</li>
</ul>