Rails

Rails ― how to populate parent object id using nested attributes for child object and strong parameters?

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a situation much like is presented in Railscast 196-197: Nested Model Form . However, I've encountered a conflict between this approach and strong parameters. I can't figure out a good way to populate the parent record id field on the child object, since I don't want that to be assignable through the form (to prevent users from associating child records to parent records they don't own). I have a solution (see code below) but this seems like the kind of thing Rails might have a clever, easy way to do for me. Here's the code... There

Rails, Docker: Host does not exist: “default”

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I try to run docker-machine start default , I get Host does not exist: "default" , I tried eval "$(docker-machine env default)" , but still getting the same message. Where is the error ? 回答1: Try simply to check what machine has been created ( docker-machine ls ): docker-machine ls Then you can pick one and try your commands with it. If there is none, you can create one first ( docker-machine create ). In the case of the OP: docker-machine create default Since the error message was: Cannot connect to the Docker daemon. Is the docker

Rails 3 - How to Create a JSON Object to store in the database

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm creating an AuditLog observer that watches over several models. I'd like the observer to have an after_create, which creates a JSON object that is stored in a database column. It will contain data like {photoid:123, photoname: "asdasd", creator_id: "asdasd"} etc... In Rails, how do I create this type of JSON object and then how do I insert it into the DB along with other non-JSON fields? Thanks 回答1: Current versions of rails support json serialisation out of the box. Define your field as a string (or text) in the migration and then:

Exception Notification Gem and Rails 3

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to get this up and running, but I see "uninitialized constant ExceptionNotifier" whenever I start my server. http://github.com/rails/exception_notification In my Gemfile I have gem "exception_notification", :git => " http://github.com/rails/exception_notification.git ", :branch => "master" I've tried putting the configuration as shown in the github readme inside of config/application.rb, config/environment.rb, and config.ru. I replaced "Whatever" with my application name. 回答1: All previous answers are outdated, you can now simply

JRuby on Rails vs. Ruby on Rails, what's difference?

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking to try out JRuby and JRuby on Rails. I'm having trouble finding information on what's difference between JRuby on Rails and Ruby on Rails. What's the differences I need to look out for? 回答1: JRuby is the ruby implementation that runs on a JVM whereas Matz's ruby is a C implementation. Key features to note are: Jruby runs on Java VM's and it's either compiled or interpreted down to Java byte code. JRuby can integrate with Java code. If you have java class libraries (.jar's), you can reference and use them from within ruby code

Rails respond_with: how does it work?

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been reading here and there about how cool the respond_with method is in Rails 3. But I can't even find a reference to it in either the Rails APIs or by searching the source. Can anyone either explain to me how it works (what options you can use, etc) or point me to the place it's actually implemented so I can peruse the code on my own? 回答1: Update for Rails 4.2+ #respond_with and ::respond_to ( n.b. class method) are no longer a part of Rails . They were migrated into the third-party responders gem as of Rails 4.2 ( release notes /

rails paperclip and passenger `is not recognized by the 'identify' command`

匿名 (未验证) 提交于 2019-12-03 02:44:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When I upload a photo, my model fails validation, err well even without any validations I'm returned this error: /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. and /tmp/stream20100103-13830-ywmerx-0 is not recognized by the 'identify' command. I'm confident this is not related to ImageMagick because I've removed any image processing from the uploading, also I've tried uploading different mime types, like .txt files and the such. Additionally, I found something that may work. A blog post claims that putting

confusing about autoload_paths vs eager_load_paths in rails 4

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I read a post about the rails load_paths, here is the link . But, I am still confused about the difference between the autoload_paths and eager_load_paths : I have tested them in a newly created Rails 4 project. It seems that they run the same way, that auto-reload in the development mode but in the production mode. 回答 1 : Author of the linked article here. Here's an attempt to clear up the confusion, going off of @fkreusch's answer. In Ruby you have to require every .rb file in order to have its code run. However, notice how in Rails you

rails generate scaffold error

匿名 (未验证) 提交于 2019-12-03 02:43:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm working on the RailsTutorial.org book and I keep hitting an error. When I run rails generate scaffold User name:string email:string I'm getting the following error: /Users/Cody/Development/rails_projects/demo_app/config/environments/development.rb:1:in `<top (required)>': undefined method `configure' for #<DemoApp::Application:0x007fdcea90ae10> (NoMethodError) I'm running Ruby 2.0.0 and Rails 4.0.4. Here is the contents of enviroments/development.rb Rails.application.configure do config.cache_classes = false config.consider_all_requests

Rails and ember with acts-as-taggable-on. How to handle relationships in JSONAPI endpoint?

匿名 (未验证) 提交于 2019-12-03 02:42:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a Rails 5 (or 4) application and I need a good tag system. First question : is acts-as-taggable-on still a good choice? This is my code: class User < ActiveRecord :: Base acts_as_taggable_on : tags end class UsersController < ApplicationController def user_params params . require (: user ). permit (: name , : tag_list ) end end @user = User . new (: name => "Bobby" ) I'm able to add and remove with this (from Rails console or code): @user . tag_list . add ( "awesome" ) @user . tag_list . remove ( "awesome" ) Second question