Android: How to edit specific record from database in Android Programming (Using Ruby on rails)

At first,I have a database created by using Ruby on rails. I just already implement insert function(HTTPPost) in my Android Application and it's work. But I don't know how to retrieve specific record from my databases and insert it back to specific record in Android (Like edit function in RoR)

This is my insert code :

private void insertComment() { DefaultHttpClient client = new DefaultHttpClient();

    HttpPost post = new HttpPost("");

    // Configure the form parameters
    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("comment[content]", t_comment.getText().toString()));
    nvps.add(new BasicNameValuePair("comment[id_account]", "1"));
    nvps.add(new BasicNameValuePair("comment[id_place]", Integer.toString(position)));

    try {
        post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block

    HttpResponse response = null;
    try {
        response = client.execute(post);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block

    HttpEntity entity = response.getEntity();
    if (entity != null) {
        try {
        } catch (IOException e) {
            // TODO Auto-generated catch block

    Toast.makeText(this, "Your post is successfully uploaded",


I really try many ways out but it doesn't work and it takes very long time to fight with this piece of code. Actually, I really don't know how to specify RowID to HTTPPost.

Can anyone help me please? Thanks in advance

Asked by: Haris369 | Posted: 25-01-2022

Answer 1

Thanks fd for your great answer. :-D

I read your comments and I got new idea.

I tried to imitate request that show in RoR console.

In the request, we have to attach the id along with data by using PUT method but I modified my insertcode above just only by chaged URL request

This mean we attach "id"=>"1" by using "action"=>"update"

This code will call POST method instead put method but it's absolutely work!!

THANKS A LOT FOR YOUR HELP ^______________^

Answered by: Elise440 | Posted: 26-02-2022

Answer 2

I'm not sure about the Android side, but from the Rails perspective I would expect you want to send a HTTP GET to your Rails application for your resource URL (eg: for comment with id 1234), ensuring you set your accept headers to prefer an XML response (you will need to define an XML view for the show action of your comment for this to work).

This should give you a response that is XML which you can decode and show in your Android app.

A similar approach should work to index your comments, for example: GET to (with an XML view defined) would give you your index of comments so you can select one to get the correct id for showing the comment.

This may not be enough if your comments are attached to some other "parent" model (for example, if they are scoped on a post), since you will also need to specify the parent you are interested in seeing the comment for.

I hope that helps!

Answered by: Audrey171 | Posted: 26-02-2022

Similar questions

android - What Programming Language is Google's Nexus One Using?

What is the initial step to start with android? How does java programming help?

Closed. This question is opinion-based. It is not c...

Android Programming Tutorials: #6

I started working through the tutorials in Mark L Murphy's book "Android Programming Tutorials". In Tutorial #6, they are starting to work with tabs. I copied the code: TabHost.TabSpec spec=getTabHost().newTabSpec("tag1"); spec.setContent(; spec.setIndicator("List", getResources() .getDrawable(R.drawable.list)); getTabHost().addTab(spec); spec=getTabHost().newTabSp...

Android programming - screen resolution

I'm new to Android programming. I've seen different phones with different screen resolutions that run on Android. How can I create an application that works on all android devices with out any distortion in my application views.....

email - Android Programming - Send mail

I'm using the following piece of code in Android to send a mail: Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setType("text/html"); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,sendTo ); emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "test" ); emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "msg" ); When code is compiled and run, its...

game programming iphone osx android 1.6 shared codebase

im planning to develop a game for iphone and android. what programming language can i use to create a shared codebase between the two platform. i understand that there are some parts which are device specific.

How to approach socket programming between C# -> Java (Android)

I've recently knocked up a server/client app for Windows &amp; Android that allows one to send a file from Windows to an android phone over a socket connection. It works great for a single file but trying to send multiple files over in a single stream is causing me problems. I've also realised that aside from the binary data, I will need to send messages over the socket to indicate error states and other applicati...

android - Some questions about using NDK for faster programming results

I have the following questions, please if you know the answers share it with me. How can I transform my working Java code to NDK? (it's an algoritm not activity) I am able to access the database from NDK? Will a backtracking algorithm with 10 millions of iterations run faster if was written with NDK?

How much Java should I have learnt before trying Android programming?

Closed. This question is opinion-based. It is not c...

How to start Android Kernel programming?

I have 6 months experience with Android, developing simple UI-based applications. Now I want to write applications targeting the Android core Kernel. For example, I want to develop a framework which is not present in Android. To achieve that, we have to write the code for the Kernel. I don't know where and how to start Android Kernel programming. If anybody knows the way to start it please help me.

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android