Tag: 的Ruby on 轨道

:dependent =>:destroy是不是在删除之前调用destroy方法?

我有一个笔记模型,具有以下关联 note.rb has_many :note_categories, :dependent => :destroy has_many :categories, :through => :note_categories 创建NoteCategory模型以用作注释和类别之间的连接表。 最初它只是一个模型/表,但我创建了一个控制器,当有人从一个笔记中删除一个类别时,做一些自定义的东西。 note_categories_controller.rb def destroy p “in notes_categories_controller destroy” note_category_to_delete = NoteCategory.find(params[:id]) #some custom stuff note_category_to_delete.destroy respond_to do |format| format.html { redirect_to(notes_url } format.xml { head :ok } end end 这很好用,因为我可以使用此链接创建一个按钮,该按钮将从注释中删除一个类别: ‘Are you sure?’, :controller => :note_categories, :method => :delete %> 它工作正常。 问题是,当我删除一个音符时,属于该音符的note_category行被删除,但是没有运行destroy方法。 […]

rails 3 link_to,ONLY_path = false

这不会提供完整的URL,因为它在邮件程序中会中断 这给了我完整的URL,这很好: false) %> 我如何充分利用这两个世界? 我想link_to但是有完整的路径? 谢谢

页面完成加载后图像消失

我使用以下代码在我的页脚中显示图像 “_blank”) %> 我看了几秒钟的图像,但在页面完全加载后,图像消失了,是否有人知道这里有什么问题? 我正在使用Rails 3.2.8和Chrome。 它不会发生在Firefox或Safari中。 谢谢 UPDATE 我不知道是什么问题。 但这就是我解决的问题。 我为此更改了图像名称和url “_blank”) %> 它解决了我的问题,但我不知道为什么。

在rails中创建下拉列表

任何人都可以帮我创建rails中的下拉列表。 我有一个带有角色字段的用户表,我想创建一个带有值管理器,调查员,角色主管的下拉列表。如何将该值提取到parms [:role]。 我是铁杆新手。

从Rails表单构建器获取数据属性值,而不使用输入字段

我有我希望成为一个简单的问题。 我需要在Edit页面上显示属性的值,同时保持相同属性的输入字段。 这怎么可能实现?

Rails:检索嵌套数据时出错

我尝试建立一个系统,在这个系统中,学生在一个与练习相关的盒子里工作。 class Student < ActiveRecord::Base belongs_to :box class Box < ActiveRecord::Base belongs_to :practice has_many :students class Practice < ActiveRecord::Base has_many :boxes 我能够保存一些测试数据,并希望通过显示框号和它的实践描述使索引页更具可读性,但我没有把它弄好。 in Practice 我得到了一个未定义的“描述”方法,虽然我可以在服务器日志中看到“正确的”SQL搜索完成。 可能是初学者的错误,但我不知道在哪里看。 任何帮助表示赞赏! 提前致谢。

如何使用Minitest测试OmniAuth的SessionsController

我正在尝试使用Minitest测试我的Facebook登录代码,但它并不顺利。 当我尝试get :auth, ‘provider’ => ‘facebook’在测试中,测试返回undefined method ‘[]’ for nil:NilClass ,如果我尝试get :new它传递,但auth不被调用。 如何使用omniauth成功重定向到auth? 这是我的源代码。 测试/控制器/ sessions_controller_test.rb require ‘test_helper’ class SessionsControllerTest ‘facebook’, ‘uid’ => ‘123451234512345’, ‘info’ => {’email’ => ‘testuser@testmail.com’, ‘name’ => ‘test’, ‘image’ => ”} }) request.env[‘omniauth.env’] = OmniAuth.config.mock_auth[:facebook] get :auth end end 应用程序/控制器/ sessions_controller.rb class SessionsController < ApplicationController def auth if(env['omniauth.params']['type'] == 'signin') if […]

安装atomic(1.1.16)时发生错误,Bundler无法继续

我正在尝试创建一个新的rails应用程序,但捆绑此错误引发… 这是我第一次遇到这个错误!! Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p448/gems/atomic-1.1.16 for inspection. Results logged to /usr/local/rvm/gems/ruby-1.9.3-p448/gems/atomic-1.1.16/ext/gem_make.out An error occurred while installing atomic (1.1.16), and Bundler cannot continue. Make sure that `gem install atomic -v ‘1.1.16’` succeeds before bundling. 我的rails版本是Rails 4.0.1 我的口碑是mac 10.9 mavericks

导轨,定制发现者

所以我希望能够使用find_by_id_or_name获取一个对象,我觉得我看到了这样的另一个问题,但我很难找到任何有关创建自己的查找器的资源。

即使我在控制器中完成了redirect_to,模板也会丢失错误

我刚开始从Agile Web Development with Rails学习Ruby on Rails。 做一个购物车应用程序,并在实现“空车”function的过程中。 单击“清空推车”按钮可调用推车控制器中的销毁操作 # DELETE /carts/1 # DELETE /carts/1.json def destroy @cart = current_cart @cart.destroy @session[:cart_id] = nil respond_to do |format| format.html { redirect_to store_url, notice: ‘Your cart is currently empty’ } format.json { head :no_content } end end 在这里,我将其重定向到store_url,但它给了我一个错误。 模板丢失缺少模板carts / destroy,application / destroy with {:locale => [:en],:formats […]