問題タブ [ruby-on-rails-5]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
ruby-on-rails - Typecasting Array value in where query possible?
I'm currently looking to implement a custom type with ActiveRecord::Type::Value following the enum implementation, using Rails 5.0.0.beta1.1.
So far I have I got it working to cast everything from and to database correctly.
Only problem I have: I want to cast a array as a whole in where()
calls, not each value.
Now, when I call for example:
... it passes each value (1
, 2
, 3
) to my serialize
method and then builds a query like
I'd rather want to decide how that call turns out, so basically that the array [1, 2, 3]
is passed to my serialize
method, not each value of it. Then I could serialize
it to an value which should simply be compared with =
:
Is this possible?
Edit: I more or less archived what I wanted by monkey patching ActiveRecord::ActiveRecord::ArrayHandler
This for now uses the protected method :type_caster
and a new added method .type_cast_where_array?
.
This new method has to be added to ActiveRecord::TypeCaster::Map:
And to make that work with default types ActiveModel::Type::Value has to be patched, too:
Now in my BitFieldType
I can override that method to return true:
Last but not least ActiveRecord::TypeCaster::Connection has to be patched with the new method too to make all tests pass.
I know the method name might not be the best and using a protected method is bad, too, but that seems to be a way to type cast array where calls without too much code changes and all activerecord tests passing.
Any comments on this?
ruby-on-rails - iOS アプリから ActionCable に接続する
私は一日中これにこだわっています。David Heinemeier Hansson による非常に単純な ActionCable サンプル アプリ (チャット アプリ) が正しく動作しています ( https://www.youtube.com/watch?v=n0WUjGkDFS0 )。
iPhoneアプリでwebsocket接続を打とうとしています。に接続すると ping を受信できますws://localhost:3000/cable
が、javascript コンテキストの外部からチャネルをサブスクライブする方法がよくわかりません。
ruby-on-rails - Rails 5. 1 つの許可キーが設定されている場合、強力なパラメーターを使用する必要はありません
Rails 5 を使用して JSON API を作成しています。
私のコントローラーは、次のような 1 つのrequire属性を持つ強力なパラメーターを使用します。
通常、次のように JSON を送信する必要があります。
必要な属性が欠落している場合、次のメッセージを取得する必要があります。
私の問題は、JSON から必要な属性を削除し、permit
強力なパラメーターと共通する属性が 1 つある場合、それが機能することです。
私が送信するJSON:
paramsを取得すると、次のようになりlog
ます。
{"permit1"=>data, "controller"=>"mycontroller", "action"=>"create", "require_attribute"=>{"permit1"=>1} }
Rails は、エラーを発生させる代わりに、必要なキーでハッシュを作成するようです。しかし、JSON を受け取ったときに必須の属性を強制したいと考えています。
誰にもアイデアがありますか?
ruby - Rails 5 アップグレード: 後に挿入するミドルウェアはありません: ActionDispatch::ParamsParser (RuntimeError)
開発中のアプリを Rails 4.2 から Rails 5 beta1.1 にアップグレードしています。アプリはアップグレード前にうまく機能しました。基本的なアップグレード手順 (Ruby の更新、Rails の更新、および関連する手順: http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html ) を完了しました。Gemfile も最新の Gem に更新されています。
$ rails middleware または $ rails console または $ rails server を実行すると、次のエラーが表示されます。
これは、ActionDispatch::ParamsParser が Rails 5 ベータ ミドルウェア ( https://github.com/rails/rails/commit/38d2bf5fd1f3e014f2397898d371c339baa627b1 ) から削除されたことに関連しています。しかし、どういうわけか、私のアプリはまだそれを探しているようです。
config/application.rb の ActionDispatch::ParamsParser を削除するなど色々試しましたが、ダメだったので追加してみました。同じエラー。このエラーを回避する方法はありますか?
ruby-on-rails - rails5 / params.merge が安全ではないというエラーを引き起こす
この構文を持つ:url_for(params.merge(locale: :en))
Rails 5はそれをブロックし、次のことを訴えます:Generating an URL from non sanitized request parameters is insecure!
同じ種類の結果を得るために、最新の適切な構文は何ですか?
ruby-on-rails-5 - どのソース パスにも「api_controller.rb」が見つかりませんでした
http://alessiofanelli.com/blog/building-a-rails-5-and-ember-js-appを使用して Rails 5 API アプリを作成しようとしています。
私は得る
api_controller.rb が見つかりませんでした
以下の scaffold コマンドの実行中にエラーが発生しました。
プロセス 32480 で Spring プリローダーを介して実行 呼び出し active_record 同一 db/migrate/20160204101609_create_teams.rb 同一 app/models/team.rb 呼び出し test_unit 同一 test/models/team_test.rb 同一 test/fixtures/teams.yml 呼び出し resource_route ルート リソース :teams 同一app/serializers/team_serializer.rb invoke scaffold_controller ソース パスのいずれにも「api_controller.rb」が見つかりませんでした。現在のソース パスは次のとおりです: /home/kpatil/.gem/ruby/gems/active_model_serializers-0.9.4/lib/active_model/serializer/generators/serializer/templates
ターミナルのメッセージの下に表示されるもの
ruby-on-rails - RSpec を使用して ActionCable チャネルをテストするにはどうすればよいですか?
ActionCable チャネルをテストする方法を知りたいです。
次のチャット チャネルがあるとします。
メソッドはsubscribed
データベースを更新し、チャネル全体にブロードキャストされる 2 つのストリームを定義しますが、私の質問はより一般的なものであるため、詳細はあまり重要ではありません。
- このチャネルをサブスクライブすることによって、関連するロジックをテストするテストをセットアップするにはどうすればよいですか?
RSpec は、コントローラー アクションなどの同様の相互作用をテストするときに、多くのヘルパー メソッドとさまざまなユーティリティを提供しますが、RSpec と ActionCable に関するものは見つかりませんでした。
ruby-on-rails - Rails 5 の ActionMailer ビュー api_only
現在、Rails API サーバーでメーラーをセットアップしようとしています。現在、次のエラーが発生します。ActionView::MissingTemplate (Missing template user_mailer/welcome_email with "mailer". Searched in:
* "user_mailer"
):
現在、次の場所にビューがありますviews/user_mailer/welcome_email.html.erb
私users_mailer.rb
の見た目は次のとおりです。
私のコントローラーは、次のようにメーラーを呼び出します。
config.api_only = false
運が悪いので設定してみました。