Tag: ruby on rails 3

在rails 3中使用button_to“delete”的bootstrap图标

我有这个编辑按钮: 我希望删除按钮看起来与此图标相同:glyphicon glyphicon-trash,但我找不到合适的语法使其工作并且看起来一样。 我的删除按钮现在: :delete, :remote=> true %>

如何使用jquery-Tokeninput和Acts-as-taggable-on

这是您使用jQuery Tokeninput和ActsAsTaggableOn自动完成的方式 。 在我的情况下,我使用嵌套的forms,但它不重要。 以下所有内容都是有效的代码。 码 产品型号: attr_accessible :tag_list # i am using the regular :tag_list acts_as_taggable_on :tags # Tagging products 产品控制器: #1. Define the tags path #2. Searches ActsAsTaggable::Tag Model look for :name in the created table. #3. it finds the tags.json path and whats on my form. #4. it is detecting the attribute […]

rails 3:如何为现有数据库表生成模型

我已经将我的database.yml配置为指向我现有的mysql数据库 我怎样才能从中生成模型? rails generate model existing_table_name 只提供一个emty模型..

设计:重定向注册失败?

我正在尝试重定向注册表单失败的用户(例如,他们输入了已经使用的用户名,他们将字段留空等等…) 我为登录表单失败的用户设置了自定义故障,代码如下: class CustomFailure < Devise::FailureApp def redirect_url root_path end def respond if http_auth? http_auth else redirect end end 但是,我一直坚持如何设置注册失败。 理想情况下,我只想将它们重定向回/ root_path,任何想法? 谢谢!

如何为一周的日历自定义表格构建器插件?

我正在使用表格构建器 https://github.com/p8/table_builder 对于我在此Rails演员中找到的日历: http://railscasts.com/episodes/213-calendars 。 我的问题是,默认情况下,日历按月显示,但我想按周显示。 有谁知道如何自定义日历的显示? 这是我的日历视图: <%= link_to " (@date.beginning_of_month-1).strftime(“%Y-%m-%d”) %> “, :month => (@date.end_of_month+1).strftime(“%Y-%m-%d”) %> @date.year, :month => @date.month do |calendar| %> :date) do |date, statuses| %> 这是控制器: class CalendarController current_user.id) @statuses = do_withs.collect { |f| f.status_id } @statuses = @statuses.collect { |f| Status.find(f) } @statuses = @statuses + current_user.statuses @statuses.flatten! @date […]

Windows / Ruby / Rails安装 – 。无法加载这样的文件–sqlite3 / sqlite3_native windows

Ruby 2.1.3p242 [x64-mingw32] Rails 4.2.0.beta2 我在64位系统上运行Windows 8。 我一直在使用c9(云托管的ubuntu),但是想在我的电脑上开始使用RubyMine IDE来使一切变得更快,但这会带来一些问题。 我已经尝试了几乎所有推荐的方式,包括这个: 如何在Windows上为Ruby安装sqlite3? 但我仍然收到相同的错误消息。 非常感谢您的帮助! 如果您对我有任何疑问,请与我们联系。 运行$ rails s时出现完整错误消息: C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `require’: cannot load such file — sqlite3/sqlite3_native (LoadError) from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `block in require’ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:233:in `load_dependency’ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/activesupport-4.2.0.beta2/lib/active_support/dependencies.rb:248:in `require’ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/sqlite3-1.3.9-x64-mingw32/lib/sqlite3.rb:6:in `rescue in ‘ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/sqlite3-1.3.9-x64-mingw32/lib/sqlite3.rb:2:in `’ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `require’ from C:/Ruby21-x64/lib/ruby/gems/2.1.0/gems/bundler-1.7.4/lib/bundler/runtime.rb:76:in `block (2 levels) in require’ […]

如何在Ruby中更改DateTime的时区?

在保持时区不变的同时读取,写入和序列化日期和时间变得令人讨厌。 我正在使用Ruby(和Rails 3.0)并试图改变DateTime的时区。 (到UTC)但不是时间本身。 我要这个: t = DateTime.now t.hour -> 4 t.offset = 0 t.hour -> 4 t.utc? -> true 我最接近的是这个,但它并不直观。 t = DateTime.now t.hour -> 4 t += t.offset t = t.utc t.hour -> 4 t.utc? -> true 有没有更好的方法?

Ruby on Rails上传文件问题奇怪的utf8转换错误

我正在尝试上传文件,我收到以下错误: “\xFF” from ASCII-8BIT to UTF-8 我正在跟踪导轨指南他们正在做什么。 这是我正在使用的代码。 file = params[:uploaded_file] File.open(Rails.root.join(‘public’, ‘images’, file.original_filename), ‘w’) do |f| f.write(file.read) end 我不明白为什么它不起作用。 我究竟做错了什么? 更新 – 这是应用程序跟踪 app/controllers/shows_controller.rb:16:in `write’ app/controllers/shows_controller.rb:16:in `block in create’ app/controllers/shows_controller.rb:15:in `open’ app/controllers/shows_controller.rb:15:in `create’

在rails中,默认的getter和setter会是什么样子?

我知道我可以编写attr_accessor:tag_list来为Rails中的对象创建一个虚拟属性tag_list。 这允许在对象的表单中存在tag_list属性。 如果我使用attr_accessor:tag_list,我可以在模型中对tag_list执行操作以从表单中提取和操作数据。 我想知道的是,如何编写一个完全复制attr_accessor默认function的getter和setter,而不是编写attr_accessor。 例如: def tag_list #what goes here end 仅供参考我尝试过 def tag_list @tag_list end 这不起作用。

Rails I18n通过数据库列

我有一个遗留数据库表,其中包含name_en和name_es列,并且想知道在ActiveRecord中根据用户的i18n首选项进行翻译的最佳方法是什么。 我在Rails中看到的i18n实现更倾向于将翻译存储在单独的散列或表中,但我不想改变数据库的结构。 目前在旧的PHP应用程序中,我向mysql查询发送一个参数来替换name_en并返回name_en或name_es AS name以便在我调用行的id时显示。