アプリ/ビュー/連絡先/show.html/erb
<%= form_for(@contact) do |f| %>
<p id="notice"><%= notice %></p>
<p>
<b>Firstname:</b>
<%= @contact.firstname %>
</p>
<p>
<b>Lastname:</b>
<%= @contact.lastname %>
</p>
<p>
<b>Email:</b>
<%= @contact.email %>
</p>
<p>
<b>Mobilephone:</b>
<%= @contact.mobilephone %>
</p>
<% end %>
<%= link_to 'Edit', edit_contact_path(@contact) %> |
<%= link_to 'List', contacts_path %>
私のview/contact/index.html.erbにはボタンがあります
<%= button_to 'show', contact %>
私のcontacts_controller.rbでは、次のような自動設定を使用しています:
def show
@contact = Contact.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @contact }
end
end
私のルートファイルで
match '/contacts/:id/edit', :controller => 'contacts', :action => 'edit'
match '/contacts/contact_:id/show', :controller => 'contacts', :action => 'show'
resources :contacts
resources :connections
resources :addresses
root :to => 'contacts#index'
そしてレーキルートを実行した後、私は得ました
/contacts/:id/edit(.:format) contacts#edit
/contacts/:id/show(.:format) contacts#show
contacts GET /contacts(.:format) contacts#index
POST /contacts(.:format) contacts#create
new_contact GET /contacts/new(.:format) contacts#new
edit_contact GET /contacts/:id/edit(.:format) contacts#edit
contact GET /contacts/:id(.:format) contacts#show
PUT /contacts/:id(.:format) contacts#update
DELETE /contacts/:id(.:format) contacts#destroy
connections GET /connections(.:format) connections#index
POST /connections(.:format) connections#create
new_connection GET /connections/new(.:format) connections#new
edit_connection GET /connections/:id/edit(.:format) connections#edit
connection GET /connections/:id(.:format) connections#show
PUT /connections/:id(.:format) connections#update
DELETE /connections/:id(.:format) connections#destroy
addresses GET /addresses(.:format) addresses#index
POST /addresses(.:format) addresses#create
new_address GET /addresses/new(.:format) addresses#new
edit_address GET /addresses/:id/edit(.:format) addresses#edit
address GET /addresses/:id(.:format) addresses#show
PUT /addresses/:id(.:format) addresses#update
DELETE /addresses/:id(.:format) addresses#destroy
root / contacts#index
そして、「表示」ボタンをクリックすると、Routes Error No route matches [POST] "/contacts/1" が表示されました。助けてくれてありがとう。