Display or conceal rendering in Rails upon clicking a button

I'm attempting to accomplish a seemingly simple task that is proving quite challenging. My goal is to conceal a render or partial in a specific view within my Rails application. Despite my efforts to find a solution, I have not come across any working examples.

Below is the snippet of code I am working with:

<p id="notice"><%= notice %></p>
<br>
<CENTER><p>
<h2>BOOK DETAILS</h2>
</p>
...

In the last line, there's a render tag (<%= render "baptism_items/form" %>) that I would like to show/hide when clicking on a link or button. Can someone provide assistance on achieving this functionality?

Answer №1

To conceal your render, simply enclose it within a div element.

<h2>Enter Game:</h2>
<div id="mydivtohide">
  <%= render "game_items/form" %>
</div>

By doing this, you can easily hide the div without affecting its contents.

Answer №2

It is important to consider whether a partial view is truly necessary in your application. To ensure that the partial does not render in the DOM at all, rather than just being hidden with JavaScript, you can define a variable in your controller like this:

render_partial? = false

Then, in your view, you can include the partial like this:

<%= render "baptism_items/form" if render_partial? %>

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

Updating Vue.js asynchronously using JavaScript import

I am facing a challenge with two form components that share a common JS validator. import { validateInput } from './validateInput.js' export default { data () { return { email: '<a href="/cdn-cgi/l/email-protection" class="_ ...

VueJS, when used in conjunction with Vuetify, might require an extra loader to handle scoped css

While attempting to compile my VueJS code using webpack, I encountered an error with the following code: <template> <v-app-bar app color="blue" flat height="100px"> <v-img class="mx-2" contain max-height="80" m ...

What is the best way to ensure that only one of two textboxes is filled out in an HTML form?

Looking to create 2 fields that are mutually exclusive. One will be a FileField and the other a TextBoxField. Is there an HTML form template available for this specific scenario? I've scoured the web but haven't come across one yet. Apologies ...

Issue with resetting input forms in ReactJS

I have a simple form that seems to be clearing the rest of the fields every time I try to fill it. Additionally, validation errors are being displayed below each field instead of just one. How can this issue be fixed? Here is how the form looks before any ...

The best way to dynamically render HTML based on screen size using server-side rendering in Vue/Nuxt

Imagine having specific markup that should only be displayed on desktop using v-if. If the user is on mobile, a different content should be shown using v-else. The vue-mq package allows for setting a default breakpoint to use for server-side rendering. ...

Error: Document's _id field cannot be modified

I am new to both MongoDB and Backbone, and I find it challenging to grasp the concepts. My main issue revolves around manipulating attributes in Backbone.Model to efficiently use only the necessary data in Views. Specifically, I have a model: window.User ...

Ways to access UserProfile in a different Dialogio

For the implementation of a chatbot, I am utilizing Microsoft's Bot Builder framework. However, upon implementing an alternative path to the dialog flow, I noticed that the user's Profile references are getting lost. Here is the code snippet fr ...

Obtaining the local IP address of my system with React JS

Is there a way to retrieve the local IP of my computer within a React JS application? I would appreciate any suggestions on how to accomplish this. ...

Is it necessary to have aria-checked attribute on a physical checkbox?

I've come across many instances of customized checkboxes that utilize the 'aria-checked' attribute. However, I am curious if it is necessary to include this attribute when using input type=checkbox? Will the checkbox still be accessible to s ...

Tips for utilizing $http and $location in custom directives

I'm completely new to working with Angular, and I have a simple question about using $http and $location in directives. I'm trying to create a task list and would like to be able to delete an entry when clicking on a link. Right now, I've a ...

Is your website's Google analytics event tracking not giving you the feedback you need

Here's what I'm trying to achieve in the code below: Set up Google Analytics on the page Add a jQuery click event based on specific query strings and domain characters Trigger a Google Analytics tracking event with the click event Implement cod ...

What is the correct way to declare this and assign values afterwards? (javascript)

I am having trouble with this code and I can't figure out how to properly declare it. var input = { container: '.slide_container', container_all: '.slide_show', slides: [] }; var $slides = $(&a ...

Utilizing Knockout bindings for populating a jQuery UI dialog through jQuery's load method

I seem to be missing a crucial point here and despite numerous attempts, I can't seem to figure it out. Currently, I am utilizing a jQuery UI dialog to generate a form popup. The form's view is stored in a separate file so when the dialog opens, ...

The use of @font-face in CSS seems to be malfunctioning

I am having trouble changing the font in my CSS to what I want it to be. body{ background-color:#a8a7a7; color:#C50909; font-family: main, Calibri; text-align:center; } @font-face{ font-family: main; src: url('fonts/RegencieLight.ttf'); } ...

The div block containing the table is experiencing horizontal overlap as additional elements are inserted

When creating a table within the div section of the code, I am incorporating text using the DRAG and DROP feature with appropriate styling. The table adjusts in size when I resize my window, indicating that it is functioning correctly. However, as the num ...

Ensuring that columns stay at a fixed width without wrapping in Bootstrap 4

I'm currently working on a layout where I want the columns to maintain a constant width when resizing the browser, without wrapping. Instead, I'd like a horizontal scroll bar to appear once it reaches the minimum width. Here's my code: < ...

Anticipating the arrival of data from an unspecified child component prior to executing the effect

Suppose there is a parent component: function Parent({ children }) { useEffet(() => { // Perform action only after all children have returned their values via props (or context) }) return <div>{ children }</div> } How do I ensure ...

When I click on the button, the output does not appear

Even though I know how to write this in pure javascript, I am new to angular so when I click submit, nothing happens and I don't get any result. index.html <input type="text" ng-model="username" placeholder="Username"> <input type=" ...

What is the best way to utilize a variable declared in a JavaScript file within an HTML document?

Here is the content of my JavaScript file: var moment = require("moment") var structuredDate = moment(Date()).format("LLLL") I am trying to dynamically update a <div> element in my HTML with the date value. This is what I attem ...

The status of "Checked" has now been set to untrue

As a beginner, I am struggling to understand how the value changes in my code. Here is a screenshot of the Material UI switch: https://i.sstatic.net/UCn2T.png In the provided code snippet, the value event.target.checked is coming from the following Switch ...