Params missing data for format.xml?

Hello there,

I have a TextSnippet model and a corresponding controller that works
perfectly fine for creating new instances via html/the browser etc.
However, when accessing it via REST/xml the “@text_snippet =[:text_snippet])” part below leaves an empty
@text_snippet, simply because params[:text_snippet] is nil for
format.xml requests. Not entirely sure why that is, but the params
only contain the following:

format => xml
action => create
controller => text_snippets
user_id => joerg-battermann

… no text_snippets in there?!

I am seriously wondering why… when accessing via the browser and
looking at the params value then, I also have

text_snippet => HashWithIndifferentAccess (2 element(s)) …

which is perfectly right.

Am I missing something?

Here’s the controller’s create action part:

class TextSnippetsController < ApplicationController

POST /users/1/text_snippets

POST /users/1/text_snippets.xml

def create
@text_snippet =[:text_snippet])

respond_to do |format|
    @user.items << @text_snippet
    flash[:success] = 'TextSnippet was successfully created.'
    format.html { redirect_to user_text_snippet_url(@user,

@text_snippet) }
format.xml { render :xml => @text_snippet, :status
=> :created, :location => user_text_snippet_url(@user,
@text_snippet) }
format.html { render :action => “new” }
format.xml { render :xml => @text_snippet.errors, :status
=> :unprocessable_entity }

Cheers and thanks,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs