Skip to content

Commit

Permalink
add 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
xdite committed May 29, 2013
1 parent 9120192 commit ed8dff1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
9 changes: 0 additions & 9 deletions manuscript/chapter-01-1-4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ end

### 解說

~~~~~~~~
def create
@group = Group.new(params[:group])
@group.save

redirect_to groups_path
end
~~~~~~~~

這邊要搭配 `app/views/groups/new.html.erb` 這個 view 並列一起看。

~~~~~~~~
Expand Down
23 changes: 23 additions & 0 deletions manuscript/chapter-01-1-6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,26 @@
end
~~~~~~~~

### 解說

這邊也要翻回 app/views/posts/edit.html.erb 這個 view 一起來看。

~~~~~~~~


<div class="span12">

<%= simple_form_for @group do |f| %>
<%= f.input :title, :input_html => { :class => "input-xxlarge"} %>
<%= f.input :description, :input_html => { :class => "input-xxlarge"} %>

<div class="form-actions">
<%= f.submit "Submit", :disable_with => 'Submiting...', :class => "btn btn-primary" %>
</div>
<% end %>

</div>

~~~~~~~~

在 RESTful Rails 的寫法中,對 `group_path` 丟 PUT 就是對應到 update 的動作。form 會背包成一個 hash,如果 @group 能夠吃進 params[:group] 進行更新且成功儲存,就會「重導」到 show action,失敗則「退回」到 edit action。
25 changes: 24 additions & 1 deletion manuscript/chapter-01-1-7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,27 @@

最後修改 `config/routes.rb`,把 root 指向 group 的 index 頁

`root :to => "groups#index"`
`root :to => "groups#index"`


{::pagebreak :/}

### 解說


這邊要翻回 app/views/posts/index.html.erb 這個 view 一起來看。

~~~~~~~~

<tr>
<td> # </td>
<td> <%= link_to(group.title, group_path(group)) %> </td>
<td> <%= group.description %> </td>
<td> <%= link_to("Edit", edit_group_path(group), :class => "btn btn-mini" ) %>
<%= link_to("Delete", group_path(group), :class => "btn btn-mini", :methpd => :delete, :confirm => "Are you sure?" ) %>
</td>
</tr>
~~~~~~~~


找到該筆資料並刪除之。在 RESTful Rails 的寫法中,對 `group_path` 丟一個 DELETE,就會對應到 destroy 的動作。可看一下 `link_to "Destroy"`那一行。

0 comments on commit ed8dff1

Please sign in to comment.