ruby-on-rails-5

not able to render form in rails association

守給你的承諾、 提交于 2020-01-26 03:54:28
问题 i created a project scaffold that has many to one association with stage scaffold now i created a task scaffold that has many to one association with stage scffold. but i task form is not rendered i am getting error. routes.rb resources :projects do resources :stages do resources :tasks end end Task form.html.erb <%= form_with(model: task, url: [@stages, task], local: true) do |form| %> <% if task.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(task.errors.count, "error") %>

symlink() NotImplementedError rabl

此生再无相见时 提交于 2020-01-25 21:29:44
问题 Adding to gemfile failed and hence I tried gem install rabl . It fails with the following error message, looks like its OS specific... I'm on Windows 7 and using Ruby 2.2 on Rails 5 api G:/Ruby/ruby/lib/ruby/site_ruby/2.2.0/rubygems/package.rb:388:in `symlink': symlink() function is unimplemented on this machine (NotImplementedError) from G:/Ruby/ruby/lib/ruby/site_ruby/2.2.0/rubygems/package.rb:388:in `block (2 levels) in extract_tar_gz' from G:/Ruby/ruby/lib/ruby/site_ruby/2.2.0/rubygems

How can I insert or store multiple ids in a single column in Rails?

和自甴很熟 提交于 2020-01-25 11:18:45
问题 How can I insert or save multiple ids as comma separated e.g (2,5,8,10) values in single column in database for many to many relationship? I am using active admin for resource management. 回答1: The has_many :through Association A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example,

Apipie receiving integer param as String

纵然是瞬间 提交于 2020-01-25 10:14:17
问题 I have the following RSpec test: it 'should not list alerts, since I do not have access to this model' do get :index, params: { model_id: @model2.id, workspace_id: @workspace.id }, as: :json expect(response).to have_http_status(:forbidden) end and it is failing because Apipie is complaining the workspace_id is a String when it is actually not, it is an Integer. I debugged the call, inspected @workspace and id is definitely an Integer. I'm seeing this issue now that I'm migrating the

Merge record into ActiveRecord Relation

╄→尐↘猪︶ㄣ 提交于 2020-01-25 06:34:05
问题 I pull a record as: def self.imp_broadcast_preview! Broadcast.where(for_gamers: true).order(:created_at).last end And then in my controller I have: def index @conversations = Conversation.where(gamer: @gamer) @conversations << Broadcast.imp_broadcast_preview! end The above code works properly in Rails 4.2 and merges the last broadcast message in the conversations. I just updated my codebase to Rails 5.2 and now I am getting an error: NoMethodError (undefined method `<<' for #<Conversation:

Rails ActionCable error during websocket handshake

拥有回忆 提交于 2020-01-24 04:00:20
问题 I'm trying to build a messaging app with Rails 5 ActionCable, but I'm getting the above error in the JS console. ws://localhost:3002/cable' failed: Error during WebSocket handshake: Unexpected response code: 404 I'm using the Redis and Puma gems. I have a Redis server running 7937:M 24 Jul 18:20:53.379 * The server is now ready to accept connections on port 6379 I start the Rails server with Puma: rails s Puma -p 3002 (is this even required?) config/cable.yml looks like this... development:

Sass Source Map in Rails 5

匆匆过客 提交于 2020-01-24 03:05:10
问题 Trying to figure out why I can’t get source maps working in Rails 5. Rails 5 uses Sass 3.4.2x, so it seems like it shouldn’t have the problem previous versions of Rails had. I’ve added the following to config/environments/development.rb # Enable source maps for Sass config.sass.inline_source_maps = true 回答1: In your Gemfile Remove gem 'sass-rails' Add gem 'sassc-rails' Enjoy Source Maps 来源: https://stackoverflow.com/questions/35370520/sass-source-map-in-rails-5

Rails(5.1.1) asset pipeline ,sprockets error

亡梦爱人 提交于 2020-01-23 03:59:08
问题 In my rails app I used three gems for authentication and styling, they are devise , twitter-bootstrap-rails and devise-bootstrap-views . After following all the steps in the guides, I started my rails server an error showed up saying The asset "apple-touch-icon-144x144-precomposed.png" is not present in the asset pipeline. What does it mean and how can I sort it out? 回答1: Revert to the original behaviour by adding Rails.application.config.assets.unknown_asset_fallback = true to the file

Storing nested objects in React State

烂漫一生 提交于 2020-01-17 08:41:09
问题 I'm getting a json from an endpoint which looks like this: {"section":{"name":"name","subsections":[ {"name":"one","snippets":[{"title":"title","body":"body"}]}, {"name":"two","snippets":[{"title":"title","body":"body"}]}] }} This is how I get the data: fetchData() { axios.get('/api/data') .then(response => { this.setState({ section: response.data.section }) }) .catch(error => { console.log(error); }); } componentDidMount() { this.fetchData(); } But when I call this.state.section.subsections

Create has_many relationships from form

回眸只為那壹抹淺笑 提交于 2020-01-17 07:05:42
问题 So if I have a two models like this: #parent.rb class Parent < ApplicationRecord has_many :children end #children.rb class Child < ApplicationRecord belongs_to :parent end How would you create a form that allows you to create multiple children in the form that creates the parent? 回答1: Cocoon[0] solves this problem quite nicely, and has a great example app. Rolling on the back-end, throw accepts_nested_attributes_for :children on your Parent model, do some fields_for (or simple_fields_for )