在rails生成器中检索生成器名称(Retrieving generator name in a rails generator)
我正在尝试设置一个rails生成器,我的第一个,在过去的两个小时里,我一直坚持一些非常简单的东西 - 如何让用户输入生成器的名称。 这是在应用程序而不是宝石。
所以在下面的例子中 - 我如何让'Foo'在生成器代码上打印?
rails g block Foo class BlockGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) puts #Foo (file name)# end
我尝试过使用NamedBase和base生成器以及我能找到的每种方法。
任何帮助将不胜感激!
#编辑$ rails g block Foo class BlockGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) argument :generator_name, type: :string puts #Foo (file name)# end #result block No value provided for required arguments 'generator_name' $ rails generate block :generator_name => testing #result is empty, nothing is printed to the console.
I'm trying to set up a rails generator, my first one, and for the past two hours I've been stuck on something really simple - How do I get the users inputed name for the generator. This is in an app and not a gem.
So in the case below - How would I get 'Foo' to print on the generator code?
rails g block Foo class BlockGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) puts #Foo (file name)# end
I've tried with both NamedBase and base generators and every method I can find.
Any help would be greatly appreciated!
# EDIT$ rails g block Foo class BlockGenerator < Rails::Generators::NamedBase source_root File.expand_path('../templates', __FILE__) argument :generator_name, type: :string puts #Foo (file name)# end #result block No value provided for required arguments 'generator_name' $ rails generate block :generator_name => testing #result is empty, nothing is printed to the console.
原文:https://stackoverflow.com/questions/40941833
最满意答案
似乎对模型进行非规范化解决了这个问题。
对于老一代设备,永远不会再为父实体执行ManagedObjects。
Seems that denormalizing the model resolved this issues.
Will not ever do ManagedObjects with a parent entity again for older generation devices.
相关问答
更多-
iOS侦测3G或WiFi(iOS Detect 3G or WiFi)[2023-09-16]
使用代码苹果在这里提供 Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier]; NetworkStatus status = [reachability currentReachabilityStatus]; if(status == NotReachable) { //No internet } else if (status == ... -
关于3G的任何简单解释(Any simple interpretation about 3G)[2022-10-12]
3G不是一项技术,而是一系列移动通信标准。 全球不同地区有不同的标准。 在美国,使用CDMA(不确定WCDMA是否也是如此),而在欧洲使用最近升级到HSPA的WCDMA(或更好地称为UMTS)。 这些都是3G家庭标准。 2G和2.5G系列标准的GPRS和EDGE是3G家族的前身。 从程序员的角度来看,所列标准GPRS,EDGE和3G(UMTS或CDMA)之间的唯一区别就是连接速度。 3G is not a single technology but a family of mobile communicat ... -
MPMoviePlayerController iPhone 3G和.mov文件格式(MPMoviePlayerController iPhone 3G & .mov file format)[2022-05-14]
3G不支持(根据我的经验,在文档中找不到它).mov。 转换为其他格式可能是最佳选择。 您可以尝试使用quicktime转换为“iPhone(手机)”,因为该格式将更小。 The 3G doesn't support (in my experience, can't find it in the docs) .mov. Converting to another format is probably the best option. You might try using quicktime to conv ... -
删除对iPhone 3G的支持(Removing support for iPhone 3G)[2022-07-17]
如果您上传的新版本没有arm6支持,则3G用户将看不到更新,并将保留在最后支持的版本上。 但是,没有安装以前版本的3G用户将无法再安装它。 如果您保留旧版本的arm6支持并创建一个仅限arm7的新应用程序ID,则3GS,4和4S用户将不得不重新下载新版本。 App Store永远不允许安装旧版本。 If you upload a new version which does not have arm6 support, 3G users will not see the update and will re ... -
根据Apple的文档 ,WiFi是首先选择的。 如果失败,则转到下一个可用(并且可能是最快的)蜂窝网络数据连接。 这是程序员在为iOS设计应用程序时不必担心的事情。 According to Apple's documentation, WiFi is what is chosen first. If that fails, then it goes to the next available (and presumably fastest) cellular network data connection ...
-
这是一段代码,可能有助于: // Matt Brown's get WiFi IP addy solution // Author gave permission to use in Cookbook under cookbook license // http://mattbsoftware.blogspot.com/2009/04/how-to-get-ip-address-of-iphone-os-v221.html + (NSString *) localAddressForInterface:(N ...
-
多任务处理和本地通知是两回事。 运行iOS4的每台设备都支持本地通知。 为了了解设备是否支持多任务处理,您可以使用它 UIDevice* device = [UIDevice currentDevice]; backgroundSupported = NO; if ([device respondsToSelector:@selector(isMultitaskingSupported)]) backgroundSupported = [device isMultitaskingSupported]; M ...
-
对于相同的iOS版本,音频框架似乎是相同的(2G除外)。 然而,物理麦克风(和声学环境)是不同的。 人们发布了各种测试结果,例如: http://blog.faberacoustical.com/2009/iphone/iphone-microphone-frequency-response-comparison/ 和 http://blog.faberacoustical.com/2010/iphone/iphone-4-audio-and-frequency-response-limitations/ ...
-
NSFetchedResultsController导致iPhone 3G冻结(NSFetchedResultsController causes iPhone 3G to freeze)[2023-09-13]
似乎对模型进行非规范化解决了这个问题。 对于老一代设备,永远不会再为父实体执行ManagedObjects。 Seems that denormalizing the model resolved this issues. Will not ever do ManagedObjects with a parent entity again for older generation devices. -
检查的最佳方法是使用sysctlbyname("hw.machine", ...) 如何判断您的代码是在iPhone还是iPhone3G上运行? 3GS的返回结果应为“iPhone2,1” The best way to check is to use sysctlbyname("hw.machine", ...) as per How to tell if your code is running on an iPhone or an iPhone3G? The returned result for 3 ...