2012-06-08 3 views
0

클라이언트에 새 메모를 게시 할 수있는 form_tag를 작성하려고합니다. 내 레이크 경로는 다음과 같다 :올바른 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 

난 그냥 노트에 작성 작업에 게시 할 수 또는 내가 new_user_note_path를 얻기 위해 필요합니까? 왜? 컨트롤러에서 사용할 수있는 @client 인스턴스 변수가 있습니다.

enter image description here

내가 요구 일이 생각 내가 하나가 명중하는 때 form_tag를 구축 할 필요가있다 : 날이 오류를 얻을 수

<%= 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 액션. 나는 new_user_note를 치는 것이 필요하다고 생각한다. 이제는 클라이언트 ID를 설정할 수있게되었다. 이 올바른지?

그렇다면 어떻게 form_tag를 구조화합니까? client_id와 함께 숨겨진 필드를 전달해야합니까?

또한 메모 작성자 컨트롤러는 새 작업 및 작성 작업과 관련하여 어떻게해야합니까?

답변

1
  1. 사용자가 자원이기 때문에, 당신의해야이 다시 자원
  2. 위한 것으로 의미로, notes#create에 의해 처리됩니다 users_notes_path:post, 사용자가 리소스이기 때문에 왜 사용자 form_for? (또는 simpleform/formtastic/whated suits)?
+0

'<% = form_for (user_notes_path) 할 | f를 | %>'gets me'일치하는 경로 없음 {: controller => "notes"}' –

1

사용자 리소스가 사용자 모델에 매핑됩니까? 그럴 경우 form_for가 최선의 방법입니다. 변수 인스턴스에 form_for 패스를 사용

<%= form_for @user do |f| %>

관련 문제