Questions tagged [ruby-on-rails-4]

If you're facing any concerns related to version 4 of Rails, feel free to ask here. In case your inquiry pertains to Ruby on Rails overall, don't forget to include the [ruby-on-rails] tag.

The Rails text area fails to load through JavaScript when a line break is detected

My comment form has a feature that displays the content of the text area using js. It functions properly unless a new line is entered in the text area, in which case it does not show up right away. However, after refreshing the page, the comment appears wi ...

What is causing the disparity between the JSON generated using the `Factory` and the one received from the `API`?

When I use my mock stub, the escaping works properly, but with the API response, the escaping does not seem to be applied for some reason. Here is a snippet of my Mock stub factory. require 'faker' F ...

Creating a js.erb file that functions independently of ajax in Ruby on Rails 4

I am currently working on a project with the following setup: index.html.erb -> link_to "click me " , 'customers/index' , :remote => true . controller -> customers def index end index.js.erb alert('in my js file'); The alert ...

Enhance the functionality of bindings in Rails 4 by implementing turbolinks

Although there are similar questions about this issue, mine seems to be caused by having the javascript tag in the head rather than the body. Moving my js outside of the page change block is not an option for me. I stick to Rails convention by organizing ...

Tips on effectively utilizing RABL partial templates while maintaining consistency

Currently working with Ruby on Rails 4 and incorporating the RABL gem into my project. I am seeking a way to reuse templates by rendering the show.json.rabl view from the index.json.rabl while following the standards outlined at jsonapi.org (source: RABL d ...

Perform a Rails Ajax request to update a like or dislike status

Is there a way to implement like/dislike functionality in my RoR application using Ajax requests? I have integer values for both like and dislike counters. How can I use Ajax requests to increment either the "like" or "dislike" counter in my methods? In ...

JavaScript event/Rails app encounters surprising outcome

I have encountered a strange bug in my JavaScript code. When I translate the page to another language by clicking on "English | Русский" using simple I18n translation, my menu buttons stop working until I reload the page. I suspect that the issue ...

Varied JSON results within RSpec

Currently, I am in the process of creating RSpec test files for a controller that exclusively responds in JSON format. The primary function of this controller is to serialize a Service object into a JSON object, and so far, this functionality is performing ...

Generating links within a popover using an array in Rails 4

Within my application, Users have the ability to recommend other Users' profiles seamlessly. The functionality related to models and associations is working perfectly, as I am able to identify which users have recommended the current_user's profile by util ...

Employing AJAX with a pair of dropdown menus in Rails version 4

In my view, I have two select boxes - one for companies and the other for employees. Both have a blank option. When a company is selected, it populates the list of employees based on that company. Everything was working fine until I encountered an issue. ...

Event handlers in JQuery are not connected through breadcrumb links

Wondering how to ensure that the click handler is always attached in my Rails 4.1 app where I am using JQuery-ujs to update cells in a table within the comments#index view. In my comments.js.coffee file, I have the following code snippet: jQuery -> ...

Nested association in Rails for rendering as JSON is a powerful feature that allows you

I have managed to solve 90% of my issue with previous questions, but I've hit a obstacle. My models include CheckIns and Person, where CheckIns are associated with People. In my controller, I currently have this code: data = CheckIn.all render json: { d ...

HTML replacement on an element cannot be done more than once. Solving the issue with Rails and JQuery Ajax

I have created an application with 4 buttons, each representing a different directory. When a button is clicked, an Ajax call is made to generate a JStree element displaying the directory hierarchy. Everything works perfectly when I click on the first but ...

AngularJS: Leveraging Devise with Several Models

I have a Rails application with two different user models that represent distinct roles (no Single Table Inheritance - each model is separate). I am considering transitioning to AngularJS for the frontend. I want to determine the most effective way to str ...

Creating a Dynamic Dropdown Menu in Rails 4

I am attempting to create a dynamic selection menu following this tutorial; however, I am encountering issues as the select statement does not seem to be updating. Below is the code snippet I currently have: #characters_controller.rb def new ...

Having difficulty including my JavaScript file located in /app/assets/javascripts when using Rails 4 and "//= require_tree ." in application.js

I'm currently attempting to implement a d3.js graph into my Rails 4 application by following a tutorial found on this website. The example application provided on GitHub works perfectly as expected. The issue I am facing is that when I try to recreate thi ...

Using a combination of Ajax and jQuery in Rails4 to showcase a date in the %m/%d/%yyyy format ultimately results in a split

Recently, I encountered an issue with an ajax call that retrieves a date from the database. The date is stored as a double in the database and then converted to a string. I used Date.parse to change it into a date object and used strftime to format it. How ...

Submitting a form with AJAX and additional fields can be accomplished by including the extra fields in

Imagine a scenario where I am working with a basic form like the one below <%= form_for(@category) do |f| %> <% if @category.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@category.errors.count, "erro ...

Displaying a collection of items using Rails, implementing form_for and integrating Ajax functionality

Looking to display a list of "Interests" for users to "follow" by clicking on a button linked to the Interest's image. Once the follow button is clicked, the Interest and its image should be removed from the list. Attempting to use a hide function in crea ...

Combining multiple models in a single view using Ruby on Rails with ajax

Currently, I am in the process of developing a Ruby-on-Rails web application that serves as a tool for tracking product technical specifications. This marks my initial attempt at creating a RoR app after completing Michael Hartl's Rails Tutorial. Despite m ...

CommentsController#new encountered a NoMethodError due to an undefined method called 'text' for the Comment with the following attributes: id: nil, author: nil, created_at: nil, updated_at: nil

I'm currently integrating rails with react to include a comments section in the app I am developing. While the /comments page is functional, I encountered an error when attempting to create a new comment. Despite consulting the guide I am following, the is ...

Generating a JavaScript variable linked to a Rails Active Record relationship

I'm trying to implement an active record association in the DOM, but I'm encountering some difficulties. Here is my editor class: .editing .row .col-sm-3 .col-sm-8 .text-left #font-20 .title-font . ...

ActiveModel::UnknownAttributeError (attribute 'order_items_attributes' is not recognized by Order model.):

Can someone please assist with this problem? ActiveModel::UnknownAttributeError (unknown attribute 'order_itens_attributes' for Order.): Here is the code from my controller: def create @order = Order.new(order_params) if @order.save ren ...

Anyone faced the issue of jquery_ujs corrupting the callback URL in Rails 4, causing problems with updating screens via Ajax?

Encountering a Catch-22 situation with jQuery in my Rails app - when I include jquery_ujs, it pulls the wrong URL from Rails during execution, leading to quiet errors when attempting to access non-existent URLs on the server. However, if I omit jquery_ujs ...

Rails gives a response of HTML when angular sends a resource.get request

Having trouble with Rails 4 responding to an angular resource.get request with HTML instead of JSON. The code snippet for the javascript is as follows: $resource("/questions/:id", {id: "@id"}}.get({id: 16}); The server error occurs because it cannot loc ...

What could be the reason my view is not updating with the use of a js.erb file in Rails 4?

I found a helpful guide on this blog to implement a toggle feature for an attribute in my database. While the toggling functionality is working fine, I'm struggling to update my view to reflect the changes. This is my first time using js.erb files so ...

View the HTML output in a Rails Ajax Call

For debugging purposes, I am trying to view the HTML response when making an AJAX request. Currently, when I check the response, I see tags like: <li>something</li> What I actually want is: Something I do not want to see the tags, just the ...

Troubleshooting Rails 4: Handling a 404 Not Found Error When Making an AJAX Call to a

After spending about an hour trying to figure this out, I am still stuck... The action in my oferts_controller.rb file looks like this: def update_categories @categories = Category.children_of(Category.find(params[:categories])) respond_to ...

Is it possible to adjust environment variables during runtime in a live production environment for a rails application?

I am currently developing a web application that focuses on automating CRUD tasks on Amazon. This includes the ability for users to delete and add addresses on their Amazon account. To automate these tasks, I am utilizing Selenium WebDriver with a Mozilla ...

The absence of the Ajax Template in Rails 4 is causing a setback

While practicing, I attempted to add a basic message form with an Ajax call. However, I encountered an error indicating that a template is missing. The error seems to be related to the Devise gem and reads as follows: Missing template messages/create, app ...

Trigger JavaScript when a specific division is loaded within a Rails 4 application

Is there a way to trigger a JavaScript function when a specific div with a certain class is loaded within my Rails 4 application? <div class="myClass"> hello world </div I am looking for a solution to execute some JavaScript code only when t ...

Unable to generate a fresh database entry through form submission

I have designed User and Pairings models as shown below: class User < ActiveRecord::Base enum role: [:student, :supervisor, :admin] has_many :students, class_name: "User", foreign_key: "supervisor_id" belongs_to :supervisor, ...

Incorporating a Bootstrap input group within a <td> element of a table

Encountering an issue when attempting to include a bootstrap input-group-addon with the input field nested inside a <td> tag within a table. Once all necessary classes are applied, there appears to be some spacing between the sign and the input field ...

Building a structured JSON request using Jbuilder

My current JSON request is returning the following data, where each person/lender has multiple inventories. #output of /test.json [ {"id":13, "email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a4cecbcccac0cbc1e4c1dcc5c ...

What is the best way to extract the created_time field from this Instagram JSON object?

After receiving this JSON data, I noticed that the created_time value displays the time in integer format instead of a proper time format. How can I convert the created_time into the correct format? "filter"=>"Normal", "created_time"=>"1421677966" ...

Create a JSON object representing a view

Working on Rails 4 and delving into the world of AJAX for my controller actions. Here's what I've come up with: def create @client = Client.new(client_params) if @client.save render :json => {:result => 'success' } else re ...

Personalize the as_json output in Ruby

Currently, I am working on building REST APIs in Ruby and utilizing @object.as_json() for the JSON response format. However, I have encountered a roadblock in customizing the data transfer within the as_json method. I have outlined my specific requirement ...

Is this conversion from PHP to Ruby code accurate?

Currently, I am in the process of integrating an API for online payments. The API is designed using PHP code, but my website operates on Ruby on Rails. Therefore, I need to convert the PHP code to Ruby. Below is the PHP code snippet: $merchant_id = &apos ...

Updating a collection_select based on another collection_select using AJAX in Rails 4

The issue: I am facing a challenge in filtering a collection of Units based on the selection of a collection of Organizations. When an Organization is selected, I want the Unit dropdown-menu to refresh and display only the Units that belong to the selecte ...

Rails not receiving JSON data

I am attempting a straightforward ajax call in Rails 4, but encountering issues with retrieving the json response. Below is the script I'm working with: $(document).on "submit", "form[name=upvote-form]", -> form = $(this) $.post "/vote", $(th ...

How can I include a query parameter in a Rails API GET request?

I'm currently working on a project with a basic Item model where both "/items" and "/items.json" are functioning properly. However, I am now looking to enhance the API by adding a search parameter like "/items.json?skuid=123" so that only Items with t ...

Show a div depending on user input

For those with more programming experience than myself, I have a simple question. In Rails, using coffescript, I want to show additional content based on a user's selection. Essentially, if they click on a checkbox, it should reveal an extra field for ...

Strategies for transmitting computed variables from a controller to JavaScript once the computation is complete?

Within my application, I have a button that triggers an action called "method" present in the UserController. This particular action involves executing some specific tasks. def method ***performing necessary calculations and operations*** @my_variable ...

Performing AJAX in Rails4 to update boolean values remotely

Suppose I have a model named Post which includes a boolean attribute called active. How can I efficiently modify this attribute to either true or false directly from the list of posts in index.html.erb using link_to or button_to helper along with remote: ...

Struggling with color styling within link_to tags in Rails 4 - having trouble getting inline styling to show up correctly

<%= link_to "Sign In", new_user_session_path, :method => :get, style: "color:white" %> <h3>Read More - <%= link_to 'Article', action: :articles, style: "color: purple" %></h3> <%= link_to 'Click to Read More Abo ...

The functionality of Kaminari Ajax paginate fails to function correctly

I'm facing an issue with the following view and controller. Despite specifying 'remote: true', kaminari is making a regular HTTP request instead of an AJAX call when navigating through the paginated links. I can't figure out what I might be missing to make ...

Using Ruby on Rails to merge multiple JSON responses from an API request

In my current project, I am facing a challenge where I need to make an API call to a client to retrieve product information by providing the product_id. Unfortunately, the client's API only allows one ID at a time, which complicates the task signific ...

Having trouble retrieving the JSON data received from the backend

After making an AJAX request, I receive a response which is then saved to a data variable. This is the controller logic: def retrieve data = params[:data] @question = Question.find_by(id: params[:question_id]) @choices = @question.choices results ...