ruby-on-rails-5.1

Pass data from Rails views to VueJS components in webpacker

荒凉一梦 提交于 2019-12-05 07:27:05
问题 I'm trying to fiddle with Rails 5.1's new webpacker gem, along with VueJS, but can't get my erb views to pass data to VueJS components... Let's say I have a user show view # view/users/show.html.erb <%= javascript_pack_tag "user-card" %> <%= content_tag :div, id: "user-card", data: { username: @user.name } do %> <% end %> And my javascript: // app/javascript/packs/user-card.js require("user-card") // app/javascript/user-card/index.js import Vue from 'vue/dist/vue.esm' import UserCard from '.

Testing POST ActionDispatch::Http::Parameters::ParseError: 765

北慕城南 提交于 2019-12-04 06:55:56
It says there's an unexpected token in my params. "ActionDispatch::Http::Parameters::ParseError: 765: unexpected token at 'conversation_identifier[participant_list][]=2&conversation_identifier[participant_list][]=1" A version of the test with magic numbers for clarity: let(:headers) do { 'HTTP_CURRENT_USER_ID' => 2, 'Content-Type' => 'application/json' } end let(:params) { { conversation_identifier: { participant_list: [1, 2] } } it 'is getting testy' do post resource_url, params: params, headers: headers assert_equal 201, response.status end Now here's what's weird. It has no trouble parsing

Pass data from Rails views to VueJS components in webpacker

谁说胖子不能爱 提交于 2019-12-03 21:48:23
I'm trying to fiddle with Rails 5.1's new webpacker gem, along with VueJS, but can't get my erb views to pass data to VueJS components... Let's say I have a user show view # view/users/show.html.erb <%= javascript_pack_tag "user-card" %> <%= content_tag :div, id: "user-card", data: { username: @user.name } do %> <% end %> And my javascript: // app/javascript/packs/user-card.js require("user-card") // app/javascript/user-card/index.js import Vue from 'vue/dist/vue.esm' import UserCard from './components/UserCard' document.addEventListener('DOMContentLoaded', () => { let element = document

Rspec request specs and Rails 5

╄→尐↘猪︶ㄣ 提交于 2019-12-03 14:43:06
I'm starting a new project, my first with Rails 5.1.0. I have a pb with my first request spec. describe 'Users', type: :request do it 'are created from external data' do json_string = File.read('path/to/test_data/user_data.json') params = { user: JSON.parse(json_string) } headers = { "CONTENT_TYPE" => "application/json" } expect do post '/api/v1/users', params.to_s, headers end.to change { User.count }.by(1) expect(response.status).to eq 200 end end this spec return the error ArgumentError: wrong number of arguments (given 3, expected 1) . The official documentation don't say much. If I take

Deploy Rails 5.1 / Webpacker app with Capistrano

匆匆过客 提交于 2019-12-03 14:24:54
I have an Ubuntu server to deploy my Rails projects. In my Ubuntu server I had RVM. Now I want to deploy new projects with Rails 5.1 and webpacker. To deploy this projects, I've installed NVM, npm and yarn in my Ubuntu server. In my Rails 5.1 / Webpacker project I have following gems for capistrano deployment: Gemfile group :development do gem 'capistrano-rails' gem 'capistrano-rvm' gem 'capistrano-passenger' gem 'capistrano-nvm', require: false gem 'capistrano-yarn' end In deploy.rb I've added some configurations for capistrano nvm and capistrano yarn. deploy.rb set :nvm_type, :user # or

Rails 5.1: “unknown firstpos: NilClass” - Issue reloading application

萝らか妹 提交于 2019-12-02 18:46:22
Following an upgrade from Rails 5.0 to 5.1 I'm getting this error anytime the app reloads, either from code changes during rails server or if I call reload! from the console. 🌶 13:53$ rc Loading development environment (Rails 5.1.1) 2.3.1 :001 > reload! Reloading... ArgumentError: unknown firstpos: NilClass from (irb):1 2.3.1 :002 > https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/journey/gtg/builder.rb Application Trace is empty, here's the Framework Trace: actionpack (5.1.1) lib/action_dispatch/journey/gtg/builder.rb:99:in `firstpos' actionpack (5.1.1) lib/action

node Issue in Creating demo project using react_on_rails gem

一曲冷凌霜 提交于 2019-12-02 17:11:16
问题 I am trying to follow this tutorial to create a dummy project using gem react_on_rails I guess I have followed every step of the tutorial but on the last step where we have to run the project a node js related error is popping up. I even updated my node version on the system, still facing the same issue Error foreman start -f Procfile.dev 22:30:58 web.1 | started with pid 5370 22:30:58 client.1 | started with pid 5371 22:30:59 client.1 | (in /home/projects/test-react-on-rails) 22:31:00 web.1

node Issue in Creating demo project using react_on_rails gem

风流意气都作罢 提交于 2019-12-02 07:38:11
I am trying to follow this tutorial to create a dummy project using gem react_on_rails I guess I have followed every step of the tutorial but on the last step where we have to run the project a node js related error is popping up. I even updated my node version on the system, still facing the same issue Error foreman start -f Procfile.dev 22:30:58 web.1 | started with pid 5370 22:30:58 client.1 | started with pid 5371 22:30:59 client.1 | (in /home/projects/test-react-on-rails) 22:31:00 web.1 | => Booting Puma 22:31:00 web.1 | => Rails 5.1.2 application starting in development on http:/

Nested Resources w/ Rails 5.1 form_with

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 07:59:26
问题 Per this pull request I can see that an array should be passed to form_with 's model param. However, when I supply the following: <%= form_with(model: [@trip, @activity], local: true) do |f| %> ... <% end %> Rails will return - ActionView::Template::Error (undefined method activity_path' for #<#<Class:0x007f80231e3070>:0x007f8023010dd8>): My routes file looks like: resources :trips do resources :activities end The output of rake routes looks like - trip_activities GET /trips/:trip_id

form_with search field in Rails 5.1

断了今生、忘了曾经 提交于 2019-11-29 09:26:34
问题 In Rails 5.1 all the forms have to be done with form_with . In http://edgeguides.rubyonrails.org/5_1_release_notes.html#unification-of-form-for-and-form-tag-into-form-with I can only find examples for forms which are related to models. What is the correct way for this Rails 5.0 form to be done in Rails 5.1 with form_with ? <%= form_tag("/search", method: "get") do %> <%= label_tag(:q, "Search for:") %> <%= text_field_tag(:q) %> <%= submit_tag("Search") %> <% end %> 回答1: Here is form_with call