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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:30:33+00:00 2026-06-18T05:30:33+00:00

i am attempting to add some ajax to a basic form, though it keeps

  • 0

i am attempting to add some ajax to a basic form, though it keeps rendering as html

Processing by OpponentsController#create as HTML

my view

<%= form_for(@opponent, :remote => true, :url => { :controller => "opponents", :action => "create" }) do |f| %>
  <% if @opponent.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@opponent.errors.count, "error") %> prohibited this opponent from being saved:</h2>

      <ul>
      <% @opponent.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

controller

# POST /opponents
  # POST /opponents.json
  def create
    @opponent = Opponent.new(params[:opponent])

    respond_to do |format|
      if @opponent.save
        format.html { redirect_to(opponents_url,
                                  :notice => "#{@opponent.name}  was successfully created.") }
        format.js { render }
      else
        format.html { render :action => "new" }
        format.json { render :json => @opponent.errors, :status => :unprocessable_entity }
      end
    end
  end

create.js.erb

alert('Hello Rails');

enter code here
  • 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-18T05:30:34+00:00Added an answer on June 18, 2026 at 5:30 am

    AJAX forms require you to have jquery and jquery_ujs loaded. Make sure you include them in your application layout header or in your application.js file like so:

    # application.js
    //= require jquery
    //= require jquery_ujs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to add a very basic (literally just a div with some text
I'm attempting to add some ajax to my pagination using the will_paginate gem as
I am attempting add some tests to an existing QT GUI application using QTest.
I am attempting to add some entities that I have created. When I try
I have am attempting to add some input fields to a jquery ui dialog
I am attempting to add a function that will create a csv for download
I'm making a Live Wallpaper and attempting to add some user preferences. If I
I'm attempting to extend a RichTextBox in order to add some functionality, and need
I'm attempting to extend a RichTextBox, so as to add some extra functionality; however,
I am attempting to add validation to my application. I have some rules I

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.