When attempting to add a respond_to in ActionController, an ActionController::UnknownFormat error

After removing respond_to and render to view, everything seems to be working smoothly, but when I include the js render, I encounter an error.

controller code :

if params[:stock].present?
  @data = params[:stock]
  @stock = Stock.new_form_lookup(params[:stock])
  respond_to do | format |
      format.js  {render partial: 'user/result'} 
  end
else
  flash[:danger] = "no search found "
  redirect_to my_portfolio_path
end

end

View code:

<%= form_tag searchstock_path , remote: true , method: :get, id:"stock-search" do %>

application.js code:

//= rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .

Answer №1

To complete this task, you should generate a new file named controller_action_name.js.erb within the view directory, and then render the partial there.

$('.className').html("<%= escape_javascript(render 'user/result') %>")

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Vue.js class bound to the object remains static even after the object is updated

When I have a number of buttons, generated using the v-for directive, with each button having an initial class based on a string from an object. There is an event that changes this string when a button is clicked. However, the class does not get updated a ...

Verify the presence of values in several textarea fields with jQuery before executing a specified action

My main goal is to validate multiple dynamic forms on a single page. If all textareas are either empty or contain default values, I need a specific function to be executed. However, if any of the textareas have content that deviates from the default value, ...

The parameters for Vue.js @change events are consistently returning as 0 whenever a file is uploaded by clicking on the picture

Check out my JSFiddle here:: https://jsfiddle.net/includephone/o9gpb1q8 I've encountered an issue involving the @change event on an input field. My goal is to create a carousel of images with 4 images per slide. Data Object Structure data: functio ...

Encountering difficulties in constructing next.js version 14.1.0

When attempting to build my next.js application, I use the command npm run build Upon running this command, I encountered several errorshttps://i.sstatic.net/5jezCKHO.png Do I need to address each warning individually or is there a way to bypass them? B ...

Guide on saving the highest score in a game using JavaScript with an if statement

I am currently working on a practice game that involves counting the number of taps made within 3 seconds. I've completed everything except for implementing the functionality to save the high score and display the previous best score if there isn&apos ...

Error encountered: Attempting to wrap MuiThemeProvider in App resulted in an invalid hook call

Whenever I include MuiThemeProvider in App.js, I encounter an error that prevents the page from loading. This issue is puzzling to me since I have utilized it successfully in other projects. react.development.js:1476 Uncaught Error: Invalid hook call. Ho ...

Contrast between pm.response.json() and parsing the responseBody using JSON.parse()

Can you explain the key distinction between const json_response = pm.response.json() and json_response = JSON.parse(responseBody) ...

Switch Tabs with Dropdown Selection

I came across a website with a similar feature, but I am interested in using a dropdown menu instead of a button or link. Check out this webpage for reference The problem seems to be related to this line of code: onchange="$('#'+$this).tri ...

Shut down the pop-up in Chrome before the DOM finishes loading

Utilizing the most recent iteration of the selenium web driver along with the Google Chrome browser, I am encountering an issue in my application. Following the click on the login button, a popup appears while the DOM is still loading. view image I simpl ...

React modules imported in ES6 not functioning as anticipated

I'm currently facing a problem when trying to import a react class into a container. The structure of my files is as follows: ├── components │ ├── Header │ │ ├── Header.js │ │ └── index.js │ └── ...

Struggling to execute a custom SQL update method in .NET through jQuery, encountering various errors like 404 and 500

I am attempting to invoke a .NET method from a JavaScript file within a Web Form project. I am uncertain if my approach is correct and I am encountering difficulties in debugging the process. .NET method: [System.Web.Services.WebMethod] public st ...

Unusual actions exhibited by a combination of JavaScript functions

Encountering an issue with a JavaScript file containing multiple functions causing strange behavior. The Logging.js file is responsible for writing to a text file: function WriteLog(message) { var fso = new ActiveXObject("Scripting.FileSystemObject") ...

Discovering the country associated with a country code using ngx-intl-tel-input

In my application, I am trying to implement a phone number field using this StackBlitz link. However, I have observed that it is not possible to search for a country by typing the country code (e.g., +231) in the country search dropdown. When I type a coun ...

Changing the name of a file using NPM

Is there a way to change the name of a specific file in npm scripts? I need to modify files for distribution, but they must have different names than the original... I attempted using orn, however it only works on the command line and not as an npm script ...

Handling errors in ASP MVC3 when using an HttpPost request

After receiving some helpful advice from @Kate and making a few tweaks, I've updated my post. Here's the original text followed by the new version: I'm working on an Ajax call to a HttpPost Action method in my ASP MVC project. The goal is t ...

Troubles arise when attempting to utilize yarn for my projects

Whenever I enter the command yarn start in the terminal, I get this output: yarn run v1.22.4 $ react-scripts start 'react-scripts' is not recognized as an internal or external command, operable program or batch file. error Command fai ...

What is a way to automatically run a function at specific intervals in PHP, similar to the setTimeout() function in JavaScript?

I have a JavaScript code snippet that looks like this: setTimeout('$.ajaxCall("notification.update", "", "GET");', 1000); Now, I want to execute the following PHP function every 1000 milliseconds, similar to the above JavaScript code: $notific ...

Understanding the response of AJAX in PHP

After exploring different ways for jQuery to interpret data in an AJAX call, I found that using JSON may be too complex for my needs. The PHP script I'm working with always returns a single integer string, sometimes followed by one or two additional ...

Is there a way for me to determine which class has been selected using jQuery and JavaScript?

I created a list containing various links: <li class="link-1"><a href="#">One</a></li> <li class="link-2"><a href="#">Two</a></li> <li class="link-3"><a href="#">Three</a></li> .. Wh ...

What is the process for displaying a document file in an iframe that is returned from a link's action?

I have a main page called index.cshtml. This page displays a list of document files along with an iframe next to it. My goal is to load the selected document file into the iframe when I click on any item in the list. However, currently, when I click on a d ...