2011-04-08 59 views
0

首先的數據表添加:我有4個表:通過另一個

1)respondentsidemail

2)inquires與ID,question_id,respondent_id

3)question_ididtext

4)answersinquiry_idtext

我想要什麼?我想做下一步:在我看來,我有questiontext_fieldbutton。 如果用戶回答問題並按下按鈕,該數據將插入answer表中。

my_controller(asnwer_controller)

def create 
    if request.post? 
     Answer.create(:inquiry_id=>@inquiry.id.to_s, :text=>params[:text]) 
    end 
    end 

my_view

<% form_for :answer, :url => { :controller => 'answer', :action => 'create' } do |f| %> 
    <%= @questions.id %>. <%= @questions.text %><br /> 
    <%= f.text_area :text, :rols => 10, :cols => 60 %><br /> 
    <%= submit_tag "Send Survey ", :class => "inputBox" %> 
<% end %> 

我到i東西視圖&控制器錯過。數據現在不粘貼。請幫忙!

+0

我通過這個幫助網頁,人們互相幫助,並不關心他們聲譽的1%,但我認爲我錯了。 – 2011-04-08 06:50:33

+0

這是真的。但是你必須表明你關心社區。當人們幫助你時,通過點擊小檢查標誌來顯示你的確認並不壞。 – Spyros 2011-04-08 07:31:12

+0

好吧!我只是在這裏呆了幾個月,我不知道這個按鈕在做什麼,現在我知道了,而且已經點擊了。 – 2011-04-08 07:33:22

回答

2

如果我明白這個問題,你想通過中間表添加數據。所以,如果用戶有很多帖子,你想添加一個帖子給用戶,對吧?如果用戶有很多帖子,並創建一個新的職位,你可以不喜歡它:

current_user.posts.create(...) 

current_user.posts << post 

希望這是你在找什麼。如果不是,請詳細說明一下。

+0

+1瞭解問題! – Dve 2011-04-21 12:37:22