ruby-on-rails-5

Combining API and web views in Rails 5

扶醉桌前 提交于 2019-12-23 09:14:12
问题 As of Rails 5, API gem is in merged in. Now, what does that leave us with in case I have API to call via AJAX from the webpage? I'm looking for a best practice here. Surely, I can make a route with JSON serializer myself. Then, there is a possibility to entirely separate API calls into another app. Since API functionality is called by inheritance class ApplicationController < ActionController::API I can't really see an option to combine the it with standard ApplicationController <

Pre-populate Rails collection_select with ajax action (Rails 5 and jQuery)

青春壹個敷衍的年華 提交于 2019-12-23 06:05:48
问题 I am trying to build an invoice app where every invoice has a line invoice item(e.g. productname, cost, amount) . I want when i select productname from the from a drop-down list in the invoice item, an ajax is fired to query the product database table with params[:product_id] , gets the product cost from the database and hence populate the item cost instantly. i.e. When a user select product name, that product cost shows up too instantly without typing it. In the attached image below, my

uninitialized constant ApplicationRecord error

空扰寡人 提交于 2019-12-23 04:53:34
问题 I am following the RailsTutorial and have been creating a Users model with appropriate attrs and validations. I've run into this error and cannot see where the problem is. The project is configured using Rails5, thus models inheriting from ApplicationRecord should be correct: User.rb: class User < ApplicationRecord before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i validates

setState inside a loop - React

旧城冷巷雨未停 提交于 2019-12-23 04:09:36
问题 I am trying to build a questionnaire in react. For now, all my answers will be accepted using the textbox. These will then be sent to my api using the ajax call. I want my params to have following structure, questionnaire: { {question: "question", answer: "answer"}, {question: "question2", answer: "answer2"}, {question: "question3", answer: "answer3"} } My code so far is really messy but somehow i'm getting the desired results. However, i'm unable to update the state of my answer and keep

ActionCable usage in Rails 5 RESTful API Development?

社会主义新天地 提交于 2019-12-23 03:43:09
问题 I am trying to create a RESTful API for the first time. Sending Request(Client to Server) and Response(Server to Client) using Action Cable. How to send request from other Applications(like Android/iOS App, Web App'n or Desktop App'n) and give response to the application. I have used Action Cable in normal Web Application. Please provide me some links with guides of ActionCable usage in Rails 5 RESTful API. Thanks in Advance. 回答1: Here is the detail to use Action Cable as Restful API. Use

Existing data serialized as hash produces error when upgrading to Rails 5

…衆ロ難τιáo~ 提交于 2019-12-22 11:35:25
问题 I am currently upgrading a Ruby on Rails app from 4.2 to 5.0 and am running into a roadblock concerning fields that store data as a serialized hash. For instance, I have class Club serialize :social_media, Hash end When creating new clubs and inputting the social media everything works fine, but for the existing social media data I'm getting: ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a ActionController::Parameters. How can I convert all of the

Existing data serialized as hash produces error when upgrading to Rails 5

非 Y 不嫁゛ 提交于 2019-12-22 11:35:17
问题 I am currently upgrading a Ruby on Rails app from 4.2 to 5.0 and am running into a roadblock concerning fields that store data as a serialized hash. For instance, I have class Club serialize :social_media, Hash end When creating new clubs and inputting the social media everything works fine, but for the existing social media data I'm getting: ActiveRecord::SerializationTypeMismatch: Attribute was supposed to be a Hash, but was a ActionController::Parameters. How can I convert all of the

Rails 5.2.1 ActiveStorage file downloads with nginx/puma are truncated

China☆狼群 提交于 2019-12-22 10:57:19
问题 My first ActiveStorage project was working fine on development (puma only) but on production (nginx/puma), i have an issue for downloading big files that appear as truncated files . For instance, an uploaded file sized 24.1 MB gives a 5 MB (truncated) download. I mostly upload pdf files, uploaded files are complete (checked on server) & the preview works fine. All environments use the config.active_storage.service = :local config/storage.yml local: service: Disk root: <%= Rails.root.join(

Getting rid of DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.0.

强颜欢笑 提交于 2019-12-22 06:53:23
问题 While migrating to Rails 5.0.0.beta1 I discovered lots of deprecation warning : DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.0. (called from XXX at YYY) I've tried to get rid of that and try to find an alternative but found nothing in the actionpack changelog. Any ideas ? 回答1: ok, so it seems that env method has been deprecated in ActionPack by this commit. so from now on we should user request.env instead of env in our controllers and helpers. 来源: https:/

ActionController::RoutingError: uninitialized constant Api::V1::ApiController

怎甘沉沦 提交于 2019-12-22 05:32:26
问题 I have Rails 5 API project for controlling user tasks and I have the following error but not always for the same controller and route. ActionController::RoutingError: uninitialized constant Api::V1::ApiController I describe you a little bit my project to explain in more detail the error. App structure Routes scope module: 'api' do namespace :v1 do # => Login routes scope module: 'login' do match 'login', to: 'sessions#login', as: 'login', via: :post end # => Team routes scope module: 'team'