2012-10-31 8 views
0

내가 할 :ActiveRecord 개체의 배열을 저장 하시겠습니까? 내보기에서

<table border="1"> 
<tr> 
    <th>Question</th> 
    <th>Counter</th> 
    <th>Lastsent</th> 
    <th>Email</th> 
    </tr> 
<% @email_stats.each do |email_stat| %> 
<% post = Post.find(email_stat.postId) %> 
    <% if post.posttype == 'Question' %> 
    <tr> 
    <td><%= post.question %></td> 
    <td><%= email_stat.counter%></td> 
    <td><%= email_stat.lastsent %></t> 
    <td><%= text_field_tag 'email', email_stat.email%></td> 
    </tr> 
    <% end %> 
</table> 

이 내가 무엇을 가지고 : 나는 테이블의 모든 레코드를 표시하고 사회자가를 입력 할 수 있도록 할 수 있도록 일부 개체를 들어, 이메일 "빈"입니다 저장을 클릭하면 이메일이 전송됩니다.

나는 form_for을 사용했지만 하나의 개체 만 저장하는 데 사용됩니다.

저장할 서버를 다시 배열로 보내는 가장 좋은 방법은 무엇입니까?

+0

email_state.post 여기 뭔가 잘못되었습니다. 'post_id' 여야합니다. –

답변

0

예상되는 동작은 form_for 대신 form_tag를 사용하여 수행 할 수 있습니다. 예

<%= form_tag :url => , :html => {:id=> , :method => , :class => ""} do %> 
    <% text_field_tag <id>, <default_value>, :name=>"post[question]" %> 
    <% text_field_tag <id>, <default_value>, :name=>"email_stat[counter]" %> 
    <% text_field_tag <id>, <default_value>, :name=>"email_stat[last_sent]" %> 
    <% text_field_tag <id>, <default_value>, :name=>"email_stat[email]" %> 
    <%= submit_tag 'save' %> 
<% end %> 

params 객체를 파라미터는 멋지게 두 모델을 업데이트 구문 분석 할 수

{'post' => {'question' => 'xxx' }, 'email_stat' => {'counter' => 'xxx' , 'last_sent' => 'xxx', 'email' => 'xxx'}} 

같은 해시 그룹화됩니다. text_field의 이름을 올바르게 지정하기 만하면됩니다.

0

아약스를 사용하면 jquery를 사용하여 테이블의 데이터를 직렬화하고 서버 측에 데이터를 다시 게시 할 수 있다고 생각합니다. 그래서 배열을 저장할 수 있습니다.

관련 문제