-1

Rails drive me crazy. I'm trying to respond to with an action with JSON. My goal is to let be the JSON the only format for a response to a URL.

Let's see some code.

The Model is a Devise user, with some added field.
The Controller is my UsersController that has this action

    # /app/controllers/users_controller.rb
    def static
        render json: current_user
    end

I got also this jbuilder view

    # /app/views/users/static.json.jbuilder
    json.content format_content(@user.content)
    json.author do
        json.name @user.name
        json.email_address @user.email
    end
    if current_user.admin?
        json.someValue "foo"
    end

this View doesn't do some interesting stuff, but It's just a try. Anyway I'll never get the static.json.jbuildercontent. I always get all Devise user's content as a JSON.

Am I doing something wrong? (or better: where I done the epic fail?)

RikyTres
  • 676
  • 9
  • 31

1 Answers1

0

Anyway found the solution:

    # /config/route.rb
    get 'my-static-json' => 'mycontroller#static', defaults: {format: :json}

 

    # /app/controllers/mycontrollers_controller.rb
    def my-static-json
    end

 

    # /app/views/mycontrollers/my-static-json.json.jbuolder
    json.content "some static content"

this is only an example but gives have all the information that I needed

RikyTres
  • 676
  • 9
  • 31