rails-api

undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fb5d1741e48>

你。 提交于 2021-02-18 06:41:31
问题 I am building a Rails-API using Omniauth-facebook and Devise-token-auth with Angular and ng-token-auth for the frontend. However when logging in with facebook I am presented with the error: undefined local variable or method `flash' for #<Devise::OmniauthCallbacksController:0x007fd027a51e10> It seems omniauth automatically uses flash middleware however the rails-api doesn't include this and I have been unsuccessfully disabling the use of flash with omniauth. My configuration is as below:

Rails 4 + Devise + Rails API: undefined method 'flash'

一曲冷凌霜 提交于 2021-02-07 07:15:57
问题 I have an existing Rails 4 application which uses Devise and Omniauth . I'm trying to modifying my existing app to develop an API (I mean I will have my web app as it is and also I want an API for mobile app) but I'm having a hard luck. I'm following the steps that are listed in Rails-API under "For already existing apps" section and now I'm getting the below error undefined method `flash' for #<Devise::SessionsController:0x000000098221d0> The error pops at this line <% unless flash.blank? %>

Rails 4 + Devise + Rails API: undefined method 'flash'

瘦欲@ 提交于 2021-02-07 07:14:13
问题 I have an existing Rails 4 application which uses Devise and Omniauth . I'm trying to modifying my existing app to develop an API (I mean I will have my web app as it is and also I want an API for mobile app) but I'm having a hard luck. I'm following the steps that are listed in Rails-API under "For already existing apps" section and now I'm getting the below error undefined method `flash' for #<Devise::SessionsController:0x000000098221d0> The error pops at this line <% unless flash.blank? %>

Rails 4 + Devise + Rails API: undefined method 'flash'

喜你入骨 提交于 2021-02-07 07:12:29
问题 I have an existing Rails 4 application which uses Devise and Omniauth . I'm trying to modifying my existing app to develop an API (I mean I will have my web app as it is and also I want an API for mobile app) but I'm having a hard luck. I'm following the steps that are listed in Rails-API under "For already existing apps" section and now I'm getting the below error undefined method `flash' for #<Devise::SessionsController:0x000000098221d0> The error pops at this line <% unless flash.blank? %>

Conditional attributes with jsonapi-serializers throwing TypeError

隐身守侯 提交于 2020-12-14 23:45:39
问题 I am working on a Ruby on Rails project with ruby-2.6.0 and Rails 6. i am working on api part, i have used jsonapi-serializers gem in my app. I want to add conditional attribute in serializer. Controller: class OrderDetailsController < Api::V1::ApiApplicationController before_action :validate_token def show user = User.find_by_id(@user_id) order_details = user.order_details.where(id: params[:id])&.first render json: JSONAPI::Serializer.serialize(order_details, context: { order_detail: true })

Conditional attributes with jsonapi-serializers throwing TypeError

牧云@^-^@ 提交于 2020-12-14 23:40:08
问题 I am working on a Ruby on Rails project with ruby-2.6.0 and Rails 6. i am working on api part, i have used jsonapi-serializers gem in my app. I want to add conditional attribute in serializer. Controller: class OrderDetailsController < Api::V1::ApiApplicationController before_action :validate_token def show user = User.find_by_id(@user_id) order_details = user.order_details.where(id: params[:id])&.first render json: JSONAPI::Serializer.serialize(order_details, context: { order_detail: true })

How can i get url of my attachment stored in active storage in my rails controller

蓝咒 提交于 2020-05-14 18:09:05
问题 How can i get url of my has_one model attachment stored in active storage in my rails controller. So, that I would be able to send it as full link as api in json. So far, I have tried following methods but each of them are giving various issues: 1) current_user.image.service_url ---- undefined method `service_url' for # 2) Rails.application.routes.url_helpers.rails_disk_blob_path(current_user.image, only_path: true) , it gives me an output like: "/rails/blobs/%23%3CActiveStorage::Attached:

How can i get url of my attachment stored in active storage in my rails controller

六月ゝ 毕业季﹏ 提交于 2020-05-14 18:08:13
问题 How can i get url of my has_one model attachment stored in active storage in my rails controller. So, that I would be able to send it as full link as api in json. So far, I have tried following methods but each of them are giving various issues: 1) current_user.image.service_url ---- undefined method `service_url' for # 2) Rails.application.routes.url_helpers.rails_disk_blob_path(current_user.image, only_path: true) , it gives me an output like: "/rails/blobs/%23%3CActiveStorage::Attached:

Use Pundit with strong parameters in Rails API

无人久伴 提交于 2020-01-16 12:03:18
问题 How is it possible to use Pundit strong parameters when working with JSON API if a model contains some relations? I have already posted a question that explained how to work around with it in case of a single model. Son here is what works: # posts_controller.rb def update if @post.update(permitted_attributes(@post)) render jsonapi: @post else render jsonapi: @post.errors, status: :unprocessable_entity end end private def set_post @post = Post.find(params[:id]) end def post_params

Use Pundit with strong parameters in Rails API

百般思念 提交于 2020-01-16 12:02:46
问题 How is it possible to use Pundit strong parameters when working with JSON API if a model contains some relations? I have already posted a question that explained how to work around with it in case of a single model. Son here is what works: # posts_controller.rb def update if @post.update(permitted_attributes(@post)) render jsonapi: @post else render jsonapi: @post.errors, status: :unprocessable_entity end end private def set_post @post = Post.find(params[:id]) end def post_params