Tag: 路径

为什么bash -l -c“CMD”让ruby找到我的gem?

在我的ruby脚本中,我需要gmail gem: require ‘rubygems’ require ‘gmail’ 在shell中运行时,它可以正常工作: ruby my-script.rb 当我把它放在一个cron作业时,它无法执行: * * * * * cd /to/script/directory;/usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/ruby ./my-script.rb 日志显示无法加载gmail gem: /usr/local/rvm/rubies/ree-1.8.7-2011.03/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require’: no such file to load — gmail (LoadError) 好吧,当我这样做时(把cmd放在bash -l -c’CMD’中): * * * * * /bin/bash -l -c ‘cd /to/script/directory;/usr/local/rvm/rubies/ree-1.8.7-2011.03/bin/ruby ./my-script.rb’ 它再次正常工作。 为什么? ps.I知道arg -l使bash成为登录shell,但这有什么不同吗?

Rails 4 – 包含供应商资产

我正在试图弄清楚如何插入一个bootstrap主题。 我有指南针轨道gem和Rails 4。 我的控制台中显示了一系列错误: Failed to load resource: the server responded with a status of 404 (Not Found) 我认为这是因为我保存供应商资产的路径不正确。 我有一个名为’profile.html.erb’的布局 在那个布局中,我包括: 引用的css文件保存在vendor / assets / stylesheets文件夹中。 错误的全文显示了以下链接: http://localhost:3000/profiles/vendor/assets/stylesheets/magnific-popup.css 额外的位是对配置文件的引用。 谁能看到我在定义这些路径时做错了什么? 进一步尝试 我刚刚发现这篇文章: 如何在Rails 4中加载供应商资产文件夹? 根据该post中的建议,我尝试更改我的application.css.scss文件,以便不使用路径引用,而是使用; @import “css/magnific-popup”; 当我保存,重新启动服务器,我收到此错误: File to import not found or unreadable: css/magnific-popup. Load paths: CompassRails::SpriteImporter CompassRails::SpriteImporter CompassRails::SpriteImporter CompassRails::SpriteImporter CompassRails::SpriteImporter CompassRails::SpriteImporter CompassRails::SpriteImporter […]

在link_to中显示的路径

我是刚刚完成rails僵尸的rails(railsforzombies.org)的新手,我正在尝试构建我的第一个应用程序(博客)。 我已经搭建了一个基本结构并进行了更改,包括更改路径,添加部分内容以及对视图的其他改进以及安装Blueprint css框架。 我遇到的问题是我的所有链接(使用link_to创建)最终看起来像这样: test post(/post/1) 在链接本身之后打印链接的路径。 但是,我无法使用链接的路径复制文本。 万一它有帮助这就是我的routes.rb看起来像: Blog::Application.routes.draw do |map| root :to => “Posts#index” match ‘/post/:id’ => ‘Posts#show’, :as => ‘show’ match ‘new’ => ‘Posts#new’, :as => ‘new_post’ 有帮助吗? 编辑: 我的link_to调用如下: 编辑: 在这张图片中可以看到问题。 此外,如果我更改为show_url,则url将显示在括号中而不是路径中。

控制器和动作中定义的路径被忽略,Ruby on Rails

根据http://guides.rubyonrails.org/layouts_and_rendering.html 我应该能够在我的micropostscontroller中的创建操作中定义来自不同控制器的路径: def create @micropost = current_user.microposts.build(params[:micropost]) if @micropost.save flash[:success] = “Micropost created!” redirect_to profile_path else render ‘static_pages/profile’ end end 但是,当我创建post失败时(将其留空或使其太长),将呈现页面’/ microposts’,即控制器不存在的主页。 当我成功创建微博时,我被重定向到配置文件路径’/ profile’,当我将render ‘static_pages/profile’更改为redirect_to profile_path ,重定向工作。 为什么浏览器会忽略渲染请求并进入微博控制器主页? 此外,渲染的微博页面提供NoMethodError: NoMethodError in Microposts#create undefined method `name’ for nil:NilClass app/views/static_pages/profile.html.erb:16:in `_app_views_static_pages_profile_html_erb___1610169404003779010_70327969935820′ app/controllers/microposts_controller.rb:10:in `create’ 当重定向到配置文件时,配置文件可以自行呈现,因为在static_pages控制器中的配置文件操作中定义了@user。 @user = User.find_by_remember_token(cookies[:remember_token])

如何在资源上命名路由?

如果我有一个带有单个动作index的控制器Home ,我知道我可以写: get ‘home’ => ‘home#index” 我将自动拥有命名路径home_path 。 但如果我这样定义它: resources :home, only: :index 我得到了路线home_index_path 。 为什么这样,如果我使用resources约定,如何创建命名路由home_path 。

Rails 4 – 带有Cocoon gem的嵌套属性

我正在尝试用Rails 4创建一个应用程序。 我正在使用Cocoon gem来创建具有简单forms的嵌套表单。 我有一个资格模型,嵌套在一个配置文件模型中。 协会是: 资格 belongs_to :profile 轮廓 has_many :qualifications accepts_nested_attributes_for :qualifications, reject_if: :all_blank, allow_destroy: true 在我的个人资料表格中,我将资格属性与以下内容相结合: 在我的资格表格属性中,我有: “Your award” %> “Are you currently studying toward this qualification?” %> “When did you graduate?”, collection: (Date.today.year – 50)..(Date.today.year + 5) %> 在我的配置文件控制器中我有: def new @profile = Profile.new @profile.qualifications_build @profile.build_vision @profile.build_personality @profile.addresses_build authorize @profile end […]

修改URL模式Ruby Rails

我正在尝试显示一个页面,以显示当前用户的所有产品。 因此,我在产品视图下创建了一个新页面showall.html.erb。 我做了以下事情: 的ProductsController def showall @products = current_user.products end 路线 resources :products do get :showall end 我知道由于URL模式的嵌套资源 /products/:product_id/showall(.:format) 我如何实际摆脱product_id部分以实现/ products / showall有一个特殊页面来呈现当前用户的所有产品。

自动将参数附加到* _url或* _path方法(Rails)

我有一组特定的视图与我的一个控制器有关,我希望任何调用*_path或*_url来附加一组参数。 是否有一些我可以覆盖的魔术方法让我这样做? 我不知道在Rails代码中甚至处理了*_path或*_url方法。 编辑为清晰起见:我正在寻找一种方法来做到这一点,这样我就不必修改每个需要发生的视图中的每个链接。 我不希望每个触及这组视图的编码器都必须记住在他们添加到页面的每个链接上附加一个参数。 应自动附加相同的参数。 我认为对*_url或*_path的更改调用失败。 同样,必须覆盖每个*_url或*_path调用都被视为失败,因为每当添加/删除新链接时都必须添加/删除新方法。

如何在Rails中将多个参数传递给嵌套路径路径?

我是Rails的新手,通常为正常的unnested路由设置一个link_to帮助器,如下所示: link_to “Delete”, article_path(article.id), method: :delete, data: {confirm: “Are you sure?”} 但是我正在学习嵌套路由,似乎我需要提供带有两个参数的路径,例如: link_to “(Delete)”, article_comments_path(comment.article_id, comment.id), method: :delete, data:{comfirm: ‘Are you sure?’} 然而,这似乎不起作用。 我已经看到你可以像这样格式化link_to : link_to ‘Destroy Comment’, [comment.article, comment], method: :delete, data: { confirm: ‘Are you sure?’ } 但这似乎让我感到困惑,因为没有定义路径,路径所需的值也没有直接指定。 是否可以格式化嵌套的link_to路径,如上面的unnested路径,还是需要格式化,如第三个例子所示? 如果是这样,有人可以尝试解释如何将此数组格式转换为Rails执行的URL? 谢谢 路线: article_comment_path – DELETE – /articles/:article_id/comments/:id(.:format) – 评论#stroy

工头立即终止

我最近在不同的计算机上安装了OSX 和 Ubuntu。 然后我尝试为两个操作系统安装redis和foreman。 这两个错误都没有标记,似乎成功执行。 但是,每当我开始领classforeman start ,我都会在两台计算机上遇到以下问题: 23:48:35 web.1 | started with pid 1316 23:48:35 redis.1 | started with pid 1317 23:48:35 worker.1 | started with pid 1318 23:48:35 redis.1 | [1317] 11 Jun 23:48:35.180 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server […]