This bit of code runs on Windows Compact Framework and what it does is obvious. It looks as it should be refactored (especially considering that I may want to add cmd.ExecuteResultSet() later), but I ...
您可以从11.31清单中重新列出第一组法典:
<section>
<%= gravatar_for @user %>
<h1><%= @user.name %></h1>
<span><%= link_to "view my profile", @user %></span>
<span><b>Microposts:</b> <%= @user.microposts.count %></span>
</section>
因为它基本上与共享的意见——用户_info.html.erb部分在主页上使用(Listing 10.32)相同。 因此,你可以把上述法典的编块改为:
<%= render shared/user_info %>
Note that you will also need to add <% @user ||= current_user %>
to the top of the viewsshared_user_info.html.erb partial (which is the same as what was necessary to add to the stats partial in Listing 11.20).
此外,在馈电-项目+与用户+微型插头部分的配料部分之间有一些重复(尽管没有准确的重复),根据该页的展示(在how、家或简介中),列出了一个或多个内容(姓名、 gr、行政删除链接、微型海报内容、微型张贴时间印章和微型删除链接)。 也许可以对这些内容进行重新评价,以便消除供料——项目+专用部分,并用视页数而定的用户+微调部分加以替换。
我刚刚通过这一努力,找到了一个行之有效的解决办法。
第一,对用户/用户/用户/用户_info.html.erb做了改动,以便在设定时使用“用户变量”和目前的用户变量。
app/views/shared/_user_info.html.erb:
<% if @user %>
<%= link_to gravatar_for(@user, size: 52), @user %>
<h1>
<%= @user.name %>
</h1>
<span>
<%= link_to "view my profile", @user %>
</span>
<span>
<%= pluralize(@user.microposts.count, "micropost") %>
</span>
<% else %>
<%= link_to gravatar_for(current_user, size: 52), current_user %>
<h1>
<%= current_user.name %>
</h1>
<span>
<%= link_to "view my profile", current_user %>
</span>
<span>
<%= pluralize(current_user.microposts.count, "micropost") %>
</span>
<% end %>
然后,我用部分用户_info.html.erb替换了 app/views/users/show_follow.hmtl.erb中的相应信息。
a. 用户/用户/show_follow.hmtl.erb:
<div class="row">
<aside class="span4">
<section>
<%= render shared/user_info %>
</section>
<section>
<%= render shared/stats %>
<% if @users.any? %>
<div class="user_avatars">
<% @users.each do |user| %>
<%= link_to gravatar_for(user, size: 30), user %>
<% end %>
</div>
<% end %>
</section>
</aside>
<div class="span8">
<h3><%= @title %></h3>
<% if @users.any? %>
<ul class="users">
<%= render @users %>
</ul>
<%= will_paginate %>
<% end %>
</div>
</div>
我希望这一答案有助于任何人通过M. Hartl的辅导。
I commonly place into variables values that are only used once after assignment. I do this to make debugging more convenient later, as I m able to hover the value on the one line where it s later ...
In Zend Frameworks tutorials, I can see form processing code like if ($request->isPost()) { $formData = $request->getPost(); $code = $request->getParam("code"); ...
I have the following pattern appearing many times in my Java code and was wondering how some of you might refactor it. Object obj1 = buildObj1(); if (obj1 != null) { return obj1; } Object obj2 = ...
As far as I know, and have gathered from other SO posts, there are no proper tools for refactoring PHP code yet, so when it comes to refactoring, it s probably good old search-and-replace for most of ...
I have a requirement that i need to load two versions of a jar at once. To avoid class path collisions I d like to rename the packages of one of the jars. Then in source you could always easily ...
I often heard from professionals blog something like refactoring your code whenever the chance you get. What is it exactly? Rewriting your code in simpler and fewer lines? What is the purpose of doing ...
I have a header file with about 400 function declarations and its corresponding source file with the definitions. In order to replace the implementation with a mock at runtime, I want to replace the ...
- winforms
- combobox
- fogbugz
- java
- date
- internationalization
- asp.net
- iis
- url-rewriting
- urlrewriter
- c#
- enums
- ocaml
- haxe
- algorithm
- string
- viewstate
- .net
- c++
- c
- symbol-table
- mysql
- database
- postgresql
- licensing
- migration
- vb.net
- vb6
- declaration
- vb6-migration
- python
- psycopg2
- backup
- vmware
- virtualization
- gnu-screen
- authentication
- desktop
- excel
- xll
- cultureinfo
- regioninfo
- oracle
- client
- session
- download
- html
- virtual
- constructor
- scenarios
- perl
- full-text-search
- javascript
- ajax
- testing
- oop
- inheritance
- vim
- encapsulation
- information-hiding