ruby-on-rails-4

How to display a Rails flash notice upon redirect?

若如初见. 提交于 2021-01-20 14:36:48
问题 I have the following code in a Rails controller: flash.now[:notice] = 'Successfully checked in' redirect_to check_in_path Then in the /check_in view: <p id="notice"><%= notice %></p> However, the notice does not show up. Works perfect if I don't redirect in the controller: flash.now[:notice] = 'Successfully checked in' render action: 'check_in' I need a redirect though... not just a rendering of that action. Can I have a flash notice after redirecting? 回答1: Remove the .now . So just write:

Rails- customize view of confirm dialog box before delete

偶尔善良 提交于 2021-01-03 22:56:44
问题 To delete a record in rails I am using this code <%= link_to "close #{user.name}'s light", light_path(id: light), method: :delete, data: { confirm: 'Are you sure?' } %> result of which, I get dialog box like this But I wants this dialog box to look like this Is there any way to customize the default view of confirm dialog box? 回答1: You can make use of bootstrap modal dialog box, like this: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div

Rails- customize view of confirm dialog box before delete

情到浓时终转凉″ 提交于 2021-01-03 22:54:32
问题 To delete a record in rails I am using this code <%= link_to "close #{user.name}'s light", light_path(id: light), method: :delete, data: { confirm: 'Are you sure?' } %> result of which, I get dialog box like this But I wants this dialog box to look like this Is there any way to customize the default view of confirm dialog box? 回答1: You can make use of bootstrap modal dialog box, like this: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div

Rails- customize view of confirm dialog box before delete

自作多情 提交于 2021-01-03 22:54:27
问题 To delete a record in rails I am using this code <%= link_to "close #{user.name}'s light", light_path(id: light), method: :delete, data: { confirm: 'Are you sure?' } %> result of which, I get dialog box like this But I wants this dialog box to look like this Is there any way to customize the default view of confirm dialog box? 回答1: You can make use of bootstrap modal dialog box, like this: <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div

How to use Ruby code inside js.erb?

萝らか妹 提交于 2021-01-03 08:42:45
问题 I'm able to render partial inside a modal using escape_javascript in js.erb file code: $("body").append("<%= escape_javascript(render partial: 'example_partial') %>"); $('#my_modal').modal('show'); However, I can't seem to get results for: console.log(<%= @error %>) 回答1: ERB will output a plain string. JS needs inverted commas around a string for it to be recognized. You have missed them on your console.log() statement. Change it to: console.log('<%= @error %>'); You may also find the raw

How to use Ruby code inside js.erb?

笑着哭i 提交于 2021-01-03 08:42:19
问题 I'm able to render partial inside a modal using escape_javascript in js.erb file code: $("body").append("<%= escape_javascript(render partial: 'example_partial') %>"); $('#my_modal').modal('show'); However, I can't seem to get results for: console.log(<%= @error %>) 回答1: ERB will output a plain string. JS needs inverted commas around a string for it to be recognized. You have missed them on your console.log() statement. Change it to: console.log('<%= @error %>'); You may also find the raw

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

孤人 提交于 2021-01-02 05:55:42
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

陌路散爱 提交于 2021-01-02 05:55:21
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

ActiveModel::Serializer::CollectionSerializer::NoSerializerError in active_model_serializer 0.10.0.rc5

自作多情 提交于 2021-01-02 05:55:14
问题 I'm using active_model_serializer 0.10.0.rc5 and grape gem for the api. I've a post endpoint like this : class V1::Endpoints::Posts < Grape::API resource :posts do desc 'Returns a list of posts.' # serializing array get '', each_serializer: V1::Serializers::PostSerializer do @posts = Post.all present @posts end end end My serializer looks something like this : class V1::Serializers::PostSerializer < ActiveModel::Serializer attributes :id, :name, :slug end Now when I try to access the post

Unable to send email as parameter in URL in Rails

早过忘川 提交于 2020-12-13 11:42:10
问题 I am writing an API to find users by email_id . I am getting an error while sending the email as a parameter. Routes.rb: Rails.application.routes.draw do namespace :api do resources :users, only: [:show, :index] , param: :email end end When I am sending the email as a parameter then I got an error. The URL is http://localhost:3000/api/users/test@abc.com: ActiveRecord::RecordNotFound in Api::UsersController#show Couldn't find User with 'id'={:email=>"test@abc"} This is my routes path: api