Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:51:55+00:00 2026-06-13T12:51:55+00:00

I have a simple Rails 3 example application that I’m trying to work out

  • 0

I have a simple Rails 3 example application that I’m trying to work out how to parse a JSON POST and insert the data into my applications database.

I have a basic Activities controller and model, the controller is as follows:

class ActivitiesController < ApplicationController
  # GET /activities
  # GET /activities.json
  def index
    @activities = Activity.order('created_at DESC').limit(10)

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @activities }
    end
  end

  # GET /activities/1
  # GET /activities/1.json
  def show
    @activity = Activity.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @activity }
    end
  end

  # GET /activities/new
  # GET /activities/new.json
  def new
    @activity = Activity.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @activity }
    end
  end

  # GET /activities/1/edit
  def edit
    @activity = Activity.find(params[:id])
  end

  # POST /activities
  # POST /activities.json
  def create
    @activity = Activity.new(params[:activity])

    respond_to do |format|
      if @activity.save
        format.html { redirect_to @activity, notice: 'Activity was successfully created.' }
        format.json { render json: @activity, status: :created, location: @activity }
      else
        format.html { render action: "new" }
        format.json { render json: @activity.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /activities/1
  # PUT /activities/1.json
  def update
    @activity = Activity.find(params[:id])

    respond_to do |format|
      if @activity.update_attributes(params[:activity])
        format.html { redirect_to @activity, notice: 'Activity was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @activity.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /activities/1
  # DELETE /activities/1.json
  def destroy
    @activity = Activity.find(params[:id])
    @activity.destroy

    respond_to do |format|
      format.html { redirect_to activities_url }
      format.json { head :no_content }
    end
  end
end

I have also got an example JSON payload from the application I’m trying to receive the POST from:

payload {"files":{"changed":[],"removed":[".gitmodules","extensions","extensions/markdown"]},"project":{"permalink":"dans-stuff-2","public_key":"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCuB80S+kMN1266LvCEXoU5hmjugcuXko61Hl7uD9VVgMgEOrLSkeYktOPshgCOwjQgGhSMVEHWrSuOddOi+V3rOu3v91jiU3vycRM3nK9GMaOFf+tTn0/4ReUvGOFHeir1vluHCmOAmpqsVhGWkCJY6eJE37muvGdTG4nW/VnpWYCTLfSOeaq5MVx5LU+zYLntvB5PXd7h1k5ROO8lW+5QzGVyHHEvilzJOqESIAWpNtcXGBt7clWpFH4lg2AT7JebYFuHl8Sl4LYzIRegcpg718CWJjrck9/xV6CBTGP520ifU6K0x4JOn/qFzVlqwnxmrPXwawptmCiYiJt3X8Oz DeployHQ.com Key for dans-stuff-2","name":"Dans Stuff","repository":{"port":null,"username":null,"branch":"master","url":"git@codebasehq.com:atech/deploytest/test1.git","scm_type":"git","cached":true,"hosting_service":{"name":"Codebase","url":"http://www.codebasehq.com","commits_url":"http://atech.codebasehq.com/projects/deploytest/repositories/test1/commits/master","tree_url":"http://atech.codebasehq.com/projects/deploytest/repositories/test1/tree/master"}}},"server":{"name":"cybele","server_path":"/home/dan/deploytest","port":22,"username":"dan","use_ssh_keys":true,"last_revision":"2ad223b9dd6d006d69909407ac7df322e35b009b","hostname":"cybele.phoenixdev.co.uk","identifier":"de99437e-da4a-0986-a7ab-e55805261a96","protocol_type":"ssh"},"start_revision":{"timestamp":"2011-11-30T13:48:22+00:00","author":"Dan Wentworth","ref":"a1c1073b85d1662c075d77f5d88be3fd291abd12","message":"nested markdown pathg","email":"dan@atechmedia.com"},"identifier":"9d0f9c21-f242-3966-fcd3-e821a65acd45","end_revision":{"timestamp":"2011-08-30T16:41:32+01:00","author":"Dan Wentworth","ref":"2ad223b9dd6d006d69909407ac7df322e35b009b","message":"arses","email":"dan@atechmedia.com"},"configuration":{"email_notify":true,"notification_addresses":"dan@atechmedia.com","copy_config_files":true},"timestamps":{"completed_at":"2012-01-17T09:22:15Z","duration":null,"queued_at":"2012-01-17T09:22:07Z","started_at":"2012-01-17T09:22:10Z"},"status":"completed"} -------------------------------------------------------------------------------- signature TMjVYhk/+lQigy3hdkgTZjAaaroxAi126XaDzrQ1xWGyMji9oR0F5nfE73Mo kNs7Hk7aY1GQgtDRdBjgPE+C/6etF9nPFXPacWobaxSP35TGOrpoSACNQDAQ Q0wvn0Bm/jMvhBKoQ6YYUSx8KP8nd7VkgQmv4S0cakgixA4LHfg=

Because the POST will need to be made to a URL, I would imagine I need to define a new method:

def deploy_receive
   data = JSON.parse(request.body)
end

What I am unsure of, is where to go from here. How would I cherry pick the attributes from the JSON and put them into various attributes in the Activities table?

Something like this?

def deploy_receive
   data = JSON.parse(request.body)
   @activity = Activity.new(params[:fault])
   @activity.who = data.author    
end

Any pointers would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:51:56+00:00Added an answer on June 13, 2026 at 12:51 pm

    If I understand correctly I think you’re looking for something like what’s below:

    Routes File

    match '/api/activity/new' => 'activity#deploy_receive', :via => [:post]
    

    Activity Controller (assuming the POSTed data is in correct format)

    def deploy_receive      
        @activity = Activity.new(params[:fault])
        if @activity.save
            render json: @activity
        else
            @activity = "error"
            render json: @activity
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple rails 2.3.4 application I am trying to get running with
I have created a simple API for a Rails application using token-based-authentication that supports
I have a Rails simple application that has two main models. A person model
I have a simple Rails 3 application that has a number of models. A
I have a simple rails application were book belongs_to user and user has_many book.
I am new to rails and have developed a simple rails application on my
I have a simple out of the box rails server running and I am
I have a Ruby on Rails application that has two active environments, Stage and
I have built a custom administration panel into a Rails application that allows content
I have a simple rails application with a few controller and some rake tasks.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.