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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:39:28+00:00 2026-06-14T06:39:28+00:00

I have a form that is adding rows to the DB via remote =>

  • 0

I have a form that is adding rows to the DB via remote => true. I then want to append the new data to a table, but cannot get the correct view to render.

As of now, it is rendering the entire show.html.erb page for the new entry, but I want to layout a minimal version to be added as a . Is there a quick way to tell my controller what view to render after inserting into the db? I want to render my partial named _newly_added.html.erb

My Controller

  def new
    @task = Task.new
    render :partial => "/tasks/newly_added", :locals => { :t => @task }
  end

Thanks!!

EDIT
I think what I need is just an alternative “show” view.

I found that the method I needed to change was actually this:

  def create
    @task = Task.new(params[:task])

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

I just need to make an alternative show view, and then tell this to redirect_to that view.

  • 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-14T06:39:29+00:00Added an answer on June 14, 2026 at 6:39 am

    Edited per the changes in your question. However, nothing really changes. You’re thinking about things wrong, and need to adjust how you’re thinking. You don’t need an alternative show, you need to handle the format.js request.

    The partial should be rendered within a JavaScript response, not the controller. The controller looks more like this:

      def create
        @task = Task.new(params[:task])
    
        respond_to do |format|
          if @task.save
            format.html { redirect_to @task, notice: 'Task was successfully created.' }
            format.json { render json: @task, status: :created, location: @task }
            format.js
          else
            format.html { render action: "new" }
            format.json { render json: @task.errors, status: :unprocessable_entity }
            format.js
          end
        end
      end
    

    Then, in views/tasks/create.js.coffee

    ($ '#mytable').append("<%= j render(partial: 'tasks/newly_added', locals: { t: @task }) %>")
    

    What’s going on here is that the browser makes a call to create.js. The controller responds with the create.js template, because of the respond_to block’s format.js. The j escapes the contents of the _newly_added.html.erb file, and the contents of it are appended to the table. The controller doesn’t interact with the existing view, instead, JavaScript is sent to the browser, and it interacts with the view.

    This all changes somewhat if you’re using a client-side MVC framework like Backbone or Ember, but you didn’t specify that so I’m assuming you’re going with stock Rails.

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

Sidebar

Related Questions

I have a form/table that is dynamically altered via JS by adding/removing rows (form
I have a table groupdentlink where I want to delete all the rows that
I have created one form that extends zend form. For Adding New Record it
I have a form that searches all rows in a single table (TServices) that
I have a table of rows and columns on an HTML-based entry form that
I have created a form that is used for both adding and editing a
I have a simple form for generating reports that I am adding a jqueryUI
I have a form that I want to be validated before showing it initially.
I have a form that the user submits and returns a result, but it
I have a form that i want to appear at the top of every

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.