Sunday, 15 July 2012

ruby on rails - form posting blank value -



ruby on rails - form posting blank value -

i'm building private message scheme (using code) on top of forum system. when new message added private message conversation body blank time-stamp , user correct.

the scheme works follows. conversation built first post , recipients. works copied verbatim question 8205284.

now i'm attempting add together new message conversation through edit/update actions in user_conversation controller (which controller builds conversation).

routes:

resources :users resources :conversations, :controller => "user_conversations" end resources :conversations, :controller => "user_conversations" resources :messages end

controller:

def edit @conversation = userconversation.find(params[:id]) @message = message.new end def update @conversation = userconversation.find(params[:id]) @message = @conversation.messages.build(params[:message]) @message.user = current_user @message.conversation_id = @conversation.conversation_id @message.body = "without test line message body blank!" if @message.save! redirect_to user_conversation_path(current_user, @conversation) else redirect_to @conversation end end

view show conversation , embedded new message form:

<%= form_for(@conversation) |c| %> <div class="field"> <%= c.fields_for :messages |m| %> <%= m.text_area :body, placeholder: "new message..." %> <%= m.submit "new convo message", class: "btn btn-large btn-primary" %> <% end %> </div> <%= c.submit "new convo message", class: "btn btn-large btn-primary" %> <% end %>

log output:

processing userconversationscontroller#update html parameters: {"utf8"=>"✓", "authenticity_token"=>"inynwro47ec6meeprkci3z95ytgkc4k7yto8wfhufns=", "user_conversation"=>{"messages"=>{"body"=>"testing"}}, "commit"=>"new convo message", "user_id"=>"18", "id"=>"18"}

i think need:

@message = @conversation.messages.build(params[:user_conversation][:messages])

because messages nested in user_conversion based on params.

messages corresponds with:

<%= c.fields_for :messages |m| %> –

ruby-on-rails

No comments:

Post a Comment