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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:41:10+00:00 2026-06-08T02:41:10+00:00

I am writing ruby on rails code. I am sending data from client to

  • 0

I am writing ruby on rails code. I am sending data from client to server using ajax request. But the problem is that it does not save that data to database. Since I am completely new to ruby on rails so I have no idea why it is not working. I also do not get any errors

Here is my code

class ContactsController < ApplicationController
def contacts
name = params["name"]
company = params["company"]
email = params["email"]
phone = params["phone"]

@contacts = Contact.new(params[:post])

if @contacts.save
  redirect_to root_path, :notice => "your post is saved"
else
  render "new"
end
end
end

Here is my js code

$('.signupbutton').click(function(e) {
        e.preventDefault();
        var data = $('#updatesBig').serialize();
        var url = 'contacts';
        console.log(data);
        $.ajax({
            type: 'POST',
            url: url,
            data: data,
            success: function(data) {
                console.log('done');
            }
        });
    });

and here is my output in console

Started POST "/contacts" for 127.0.0.1 at 2012-07-13 13:25:41 +0300
Processing by ContactsController#contacts as */*
  Parameters: {"name"=>"asdsa", "company"=>"asdsa", "email"=>"asdasd", "phone"=>"asdasd"}
   (0.1ms)  begin transaction
  SQL (18.1ms)  INSERT INTO "contacts" ("company", "created_at", "email", "group", "name",  "phone", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["company", nil], ["created_at", Fri, 13 Jul 2012 10:25:41 UTC +00:00], ["email", nil], ["group", nil], ["name", nil], ["phone",  nil], ["updated_at", Fri, 13 Jul 2012 10:25:41 UTC +00:00]]
   (3.9ms)  commit transaction
Redirected to http://0.0.0.0:3000/
Completed 302 Found in 33ms (ActiveRecord: 22.5ms)

Update

Here is my html form. I am using haml instead of plan html.erb

%form#updatesBig{:target => 'contacts', :method => 'post'}
    %div
      %label{:for => 'form_updatesBig_name'} Name
      %input{:type => "text", :id => 'form_updatesBig_name', :name => 'name', :class => 'text name required'}
      %label{:for => 'form_updatesBig_company'} Organization
      %input{:type => "text", :id => 'form_updatesBig_company', :name => 'company', :class => 'text company required'}
    %div
      %label{:for => 'form_updatesBig_email'} E-mail
      %input{:type => "text", :id => 'form_updatesBig_email', :name => 'email', :class => 'text email required'}
      %label{:for => 'form_updatesBig_phone'} Phone
      %input{:type => "text", :id => 'form_updatesBig_phone', :name => 'phone', :class => 'text phone required'}
    %div
      %input.button.signupbutton{:type => 'submit', :value => 'Sign up'}
  • 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-08T02:41:12+00:00Added an answer on June 8, 2026 at 2:41 am

    It looks like your HTML input names and your controller are not working together. Normally in Rails, when you use the built-in form helpers, all the field names are namespaced with your model:

    <input name="contact[name]">
    

    This is what allows you do things like Contact.new(params[:contact]) in your controller. In your case I can’t tell what is going on with the form since you didn’t post it, but I’m assuming based on how you are accessing the params variables in your controller, this is the issue. I would recommend using the form helpers so your HTML follows the expected convention of namespaced params. Then you’ll be able to change your controller to:

    @contacts = Contact.new(params[:contact])
    
    if @contacts.save
      redirect_to root_path, :notice => "your post is saved"
    else
      render "new"
    end
    

    One thing to watch out for is that instantiating objects blindly using params can lead to security holes. Make sure you read the security guide section on mass-assignment to understand this better.

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

Sidebar

Related Questions

I'm writing an Ruby on Rails app using a legacy database. The problem I'm
I am writing a Ruby on Rails site which loads some data from an
I am writing some Ruby code, not Rails, and I need to handle something
In a fit of unoriginality, I'm writing a blog application using Ruby on Rails.
I'm writing a Rails app that needs to convert an IDN domain name from
I'm writing a ruby on rails application using mongoid and I'm wondering about the
I have an app that is using devise for authentication. Rails 3 on ruby
I'm writing some ruby (not Rails) and using test/unit with shoulda to write tests.
I'm currently writing an application in ruby on rails that uses AWS. I see
I'm writing a Ruby on Rails app. The following jQuery code is included in

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.