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 6624241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:43+00:00 2026-05-25T21:37:43+00:00

Ok, in PHP I can do this in 5 minutes. With Rails I am

  • 0

Ok, in PHP I can do this in 5 minutes. With Rails I am completely lost. I am so new to Rails and I have a requirement to do more advanced stuff with it then I am comfortable with currently. The Big guy decided lets go Rails from PHP. So its crash course learning. Fun times..

I understand from the javascript side making the post/get with jquery remains the same. On the ruby side however I am completely lost. What do I need to do in order to do a post/get to a Rails App. How would I define my controller? Lets say from the HTML side I am posting

input1 and input2 standard jquery $.post with a JSON request for data back. With php I would make a simple controller like:

public function myFormPostData(){
    $errors = "none";
    $errorMsg = "";
    if($_POST['input1'] == ""){$errors = "found"; $errorMsg .= "Input 1 Empty<br>";}
    if($_POST['input2'] == ""){$errors = "found"; $errorMsg .= "Input 2 Empty<br>";}

    if($errors == "found"){ $output = array("error" => "found", "msg" => $errorMsg); }
    else{
        $output = array("error" => "none", "msg" => "Form Posted OK!!"); 
    }
  echo json_encode($output);
}

but in ruby I dunno how to translate that concept. I’m open to suggestions and good practices. Grant it the above is a super mediocre rendition of what I am needing to do I would sanitize things more than that and all else, but it gives the idea of what I am looking for in Rails..

  • 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-05-25T21:37:43+00:00Added an answer on May 25, 2026 at 9:37 pm

    First of all, Rails 3 has a nice feature called respond_with. You might check out this Railscast episode that talks about it. http://railscasts.com/episodes/224-controllers-in-rails-3. The examples he uses are great if you are dealing with resources.

    Having said that, I’ll give you an example with a more traditional approach. You need to have a controller action that handles requests which accept JSON responses.

    class MyController < ApplicationController
      def foo
        # Do stuff here...
        respond_to do |format|
          if no_errors? # check for error condition here
            format.json { # This block will be called for JSON requests
              render :json => {:error => "none", :msg => "Form Posted OK"}
            }
          else
            format.json { # This block will be called for JSON requests
              render :json => {:error => "found", :msg => "My bad"}
            }
          end
        end
      end
    end
    

    Make sure that you have a route set up

    post '/some/path' => "my#foo"
    

    Those are the basics that you will need. Rails gives you a lot for free, so you may find that much of what you are looking for already exists.

    If you post a more concrete example of what you are trying to you might get even better advice. Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been staring at this for 20 minutes now and I can't figure
I was wondering if PHP can do this as there seems to be no
I've noticed recently in PHP you can do this. $myNewArray = $oldArray + $someArray;
How can I this PHP function include in jquery .html? PHP function: function trim_text($string,
I'm a bit confused with this: can I use PHP variables in a pg
This is a bit hard for me to articulate, but in PHP you can
How can I do this Perl code in PHP? print unpack (H*, pack (B*,
How can I do this in Javascript/jQuery from PHP? I am trying to populate
I am using the SQL Server PHP Driver, I think this question can be
Can anyone help me with reversing this PHP page navigation? Current script setting shows

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.