ruby-on-rails-5

How to upload a file in a Rails Rspec request spec

China☆狼群 提交于 2020-01-01 08:29:09
问题 I want to test uploading a file in a Rails Rspec request test. I'm using Paperclip for asset storage. I've tried: path = 'path/to/fixture_file' params = { file: Rack::Test::UploadedFile.new(path, 'application/pdf', true) } post v1_product_documents_path, params: params In the controller, I get a string "#Rack::Test::UploadedFile:0x0055b544479128>" instead of the actual file. The same code works in controller tests 回答1: try to use fixture_file_upload : fixture_file_upload or if you wanted to

Separate secret_key_base in Rails 5.2?

我的未来我决定 提交于 2020-01-01 08:05:02
问题 I just upgraded from 5.1 to 5.2 and I'm quite confused about this 'better' methodology to storing secrets... Maybe I'm not understanding, but it seems like now development and production have been 'merged' into a SINGLE SECRET_KEY_BASE as well as master.key ... is this correct? If not, how do I use a separate master key and SECRET_KEY_BASE in development? What if I have developers helping me and I don't want them to know my master key (or secrets) I use in production? 回答1: Rails 5.2 changed

Separate secret_key_base in Rails 5.2?

核能气质少年 提交于 2020-01-01 08:04:13
问题 I just upgraded from 5.1 to 5.2 and I'm quite confused about this 'better' methodology to storing secrets... Maybe I'm not understanding, but it seems like now development and production have been 'merged' into a SINGLE SECRET_KEY_BASE as well as master.key ... is this correct? If not, how do I use a separate master key and SECRET_KEY_BASE in development? What if I have developers helping me and I don't want them to know my master key (or secrets) I use in production? 回答1: Rails 5.2 changed

ActionCable: How to use dynamic channels

人走茶凉 提交于 2020-01-01 06:45:42
问题 I have built a simple chat with Rails 5 and ActionCable where i have one simple "chat" channel. How can i make the channel subscription and message broadcasting dynamic, so i can create chat channels and have the messages go to the right channels? I cannot find a single code example of this unfortunately. Update The answer below is correct. I also found it now mentioned in the rails guide. Don't think it was there before http://edgeguides.rubyonrails.org/action_cable_overview.html#client

rails c not working in rails 5

馋奶兔 提交于 2020-01-01 01:48:09
问题 On using the command in terminal inside a rails 5 application rails c the error thrown is given bellow. I have no idea what this means in a similar question here that for which the solution was to use spring stop. I have tried that too but no it still gave the same error. it would be great if somebody can point out the mistake here. Running via Spring preloader in process 6457 /Users/AmanChawla/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in `require'

What’s does the [5.0] in Rails 5’s ActiveRecord::Migration mean?

与世无争的帅哥 提交于 2019-12-30 07:53:13
问题 A migration I created in a Rails 5 application had 5.0 passed into a method: class CreateVariableKeys < ActiveRecord::Migration[5.0] ... end I would like to know what the [5.0] means. 回答1: It is a class method of ActiveRecord::Migration and is defined here. It allows us to select the version of migrations we wish to use between 4.2 and 5.0 . The method throws a: "Unknown migration version ... " error if an incompatible version is passed as an argument. Production ready versions of

Unable to set session hash in Rails 5 controller test

故事扮演 提交于 2019-12-28 22:03:33
问题 According to the Rails Edge Guide all ActionDispatch::IntegrationTest HTTP requests take optional named keyword arguments: get post_url, params: { id: 12 }, session: { user_id: 5 } Great. Now, I've got the following code in a controller test: test 'should redirect from login page if user is logged in' do get '/login', session: { user_id: users(:stephen).id } assert_redirected_to root_url, 'Expected redirect to root' end And when I run it, my test fails and I see the following deprecation

Devise login with computed / manipulated username param

落花浮王杯 提交于 2019-12-25 18:41:12
问题 I'm trying to create a login using devise with a username that I've computed. As an example, let's assume we want to namespace our usernames - and I want to receive a username from the login form, and use namespaced_username to do the actual authentication. So in my User::SessionsController#create , I might have: def create params[:user][:namespaced_username] = "namespace/#{params[:user][:mobile_number]}" super end Even though devise is listening for namespaced_username (configured with

How to fix undefined method `form_with' in my search bar when building out Global Autocomplete Search?

£可爱£侵袭症+ 提交于 2019-12-25 15:55:31
问题 I get a strange error when trying to run a global autocomplete search across multiple models in my rails App and leveraging the easy-autocomplete jquery library along with the ransack gem for search. Specifically, I believe the error is in my navbar page as I get this error when I try to run a query- undefined method form_with for #<#<class:0x007f875a6f8b58>:0x007f87600e0aa8> I decided to hack away and switch form_with for form_tag but then I get an error on the line immediately below

Can't get the 'Follow' button to work with Acts_As_Follower

为君一笑 提交于 2019-12-25 15:55:25
问题 I'm using Acts_as_follower in a wishlist app I'm working on. I think it should be working, but the button to actually follow another user is not. The follow button is in my user index view, and I can see it there, but it doesn't respond to being clicked. Any help would be appreciated. Here's my code: index.html.erb <div class="container"> <% @users.each do |u| %> <div class="col-sm-8 col-lg-4"> <div id="gifts"> <div class="box panel panel-default"> <h2><%= link_to u.name, u %></h2> <p> <table