クライアントに新しいメモを投稿できる form_tag を作成したいと考えています。私のレーキ ルートは次のようになります。
[hchq (master)]$ rake routes
user_notes GET /users/:user_id/notes(.:format) notes#index
POST /users/:user_id/notes(.:format) notes#create
new_user_note GET /users/:user_id/notes/new(.:format) notes#new
edit_user_note GET /users/:user_id/notes/:id/edit(.:format) notes#edit
user_note GET /users/:user_id/notes/:id(.:format) notes#show
PUT /users/:user_id/notes/:id(.:format) notes#update
DELETE /users/:user_id/notes/:id(.:format) notes#destroy
users GET /users(.:format) users#index
POST /users(.:format) users#create
new_user GET /users/new(.:format) users#new
edit_user GET /users/:id/edit(.:format) users#edit
user GET /users/:id(.:format) users#show
PUT /users/:id(.:format) users#update
DELETE /users/:id(.:format) users#destroy
sessions POST /sessions(.:format) sessions#create
new_session GET /sessions/new(.:format) sessions#new
session DELETE /sessions/:id(.:format) sessions#destroy
clients GET /clients(.:format) clients#index
POST /clients(.:format) clients#create
new_client GET /clients/new(.:format) clients#new
edit_client GET /clients/:id/edit(.:format) clients#edit
client GET /clients/:id(.:format) clients#show
PUT /clients/:id(.:format) clients#update
DELETE /clients/:id(.:format) clients#destroy
root / clients#index
signup /signup(.:format) users#new
signin /signin(.:format) sessions#new
signout DELETE /signout(.:format) sessions#destroy
メモの create アクションに投稿するだけでよいですか、それとも new_user_note_path を取得する必要がありますか? なんで?コントローラーで @client インスタンス変数を使用できます。
これは私が現在持っているものです:
<%= form_tag(new_user_note_path, method: :get) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Compose new note" %>
</div>
<%= f.submit "New Note"%>
<% end %>
このエラーが発生します:
私が必要だと思うのは、コントローラーの create または new_user_note アクションにヒットする form_tag を作成する必要があるということです。クライアントIDを設定できるように、さらに考えてみると、new_user_noteにヒットする必要があると思います。これは正しいです?
その場合、form_tag をどのように構成すればよいですか? 非表示フィールドに client_id を渡す必要がありますか?
また、新しいアクションと作成アクションに関して、ノート コントローラーはどのように見えるべきでしょうか?