Rails

Rails 4: How to upload multiple images using carrierwave

匿名 (未验证) 提交于 2019-12-03 09:58:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I can upload a file with using carrierwave as shown in the following code. How can I edit the code to make it possible to upload images up to 3 files in one article? views\articles\new.html.erb . . < div class = "span8" > <%= render 'shared/article_form' %> </ div > . . views\shared\ _article_form.html.erb . . <%= form_for ( @article ) do | f | %> < div class = "field" > <%= f . hidden_field : category_id %> <%= f . fields_for : photos do | p | %> <%= p . hidden_field : article_id %> <% if p . object . image and p . object . image

is there a rails method to loop through each line of uploaded file? “each_line” is an IO method but it's not working

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm attempting to upload a csv file, parse it, and spit out a file for S3 or just pass to view. I use a file_field_tag to upload the csv. I thought file_field_tag passes an object that is a subclass of IO and would have all ruby IO methods such as "each_line". I can call "read" on the object (method of IO class) but not "each_line"... so how can I iterate over each line of a file_field_tag upload? create method of my controller as: @csv_file = params [: csv_file ] My show view which throws a no "each_line" method error: <% @csv

Rails time_ago_in_words producing bad output

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I thought this might be due to moving to activesupport 2.3.5 but now I believe something else must have happened. Model has a valid rfc822 style date: >> s.lastVisitDate => "Thu, 06 Jan 2011 22:24:10 -0800" But in my view: <%=h time_ago_in_words(@site.lastVisitDate) -%> renders: *about {{count}} hours ago* instead of: *about 2 hours ago* which was working just fine earlier. Wondering if anyone else has seen this behavior. I've reviewed my version history for the model and view and nothing has changed recently so I believe I must have messed

Why does Rails / ActiveRecord gives a Postgres SyntaxError “non-integer constant in ORDER”?

匿名 (未验证) 提交于 2019-12-03 09:52:54
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some Ruby on Rails / ActiveRecord code that is giving me the following Postgres error: PG::SyntaxError: ERROR: non-integer constant in ORDER I'm not sure why since it is a simple fetch ordered by created_at self.posts.order(created_at: :desc).limit(25) What do I do to change this? 回答1: I am not sure that syntax is supported in older versions of Rails, which is where I suspect you are. Try this instead: self.posts.order("created_at desc").limit(25) 回答2: I have experienced this error as well after switching my Rails app from MySQL to

NameError: uninitialized constant ActionController::Dispatcher

匿名 (未验证) 提交于 2019-12-03 09:21:58
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Found a similar post here but I am running a Mac so the first solution does not exactly apply and the second didn't work for me. Running Mac OS 10.7.2, Xcode 4.2.1, rvm 1.10.1 using ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0] I believe the issue to due with rvm, however I do not know how to fix it $ rails new dispatch_me $ rails generate controller demo index $ rails console Loading development environment (Rails 3.2.0.rc2) 1.9.3-p0 :001 > env = {} => {} 1.9.3-p0 :002 > env['REQUEST_METHOD'] = 'GET' => "GET" 1.9.3-p0 :003

利用vagrant快速搭建rails开发环境

半城伤御伤魂 提交于 2019-12-03 09:21:33
Deprecated 前言 当我们学习一门新的语言或技术的时候,最麻烦或比较浪费时间的事情就是搭建开发环境。而搭建开发环境与我们将要学习的新的语言或技术,没有太大的联系,因为我们感兴趣的只是新的语言或技术本身,而并非它们的开发环境。如果浪费太多的时间在这些上面,则更是不值得事情。如果能有一套现成的搭建好的开发环境,这样我们就可以直接关注我们所感兴趣的东西了。如在写某方面教程的时候,如果能配有一个现成的开发环境,这样初学者就可以快速的上手,掌握核心的知识,聚焦重点内容。 本文主要介绍如何利用vagrant快速的搭建rails开发环境,体验rails开发的敏捷。我觉得程序员不应该拒绝新的技术,当您能够快速的体验它的时候,也许你就会被她所深深的吸引。 step0 安装vagrant windows vagrant.msi 按照步骤默认进行安装即可。 mac vagrant.dmg 按照步骤默认进行安装即可。 step1 安装virtualbox https://www.virtualbox.org/wiki/Downloads step2 安装rails环境 vagrant box add centos http://nb.baidupcs.com/file/6c3d2269163cbf50bb1c74701c2c4014?bkt=p2-nb-191&fid=992976907

Rails button_to No route matches {:action=&gt;“complete”, :controller=&gt;“dashboard”, :name=&gt;“Order”}

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Please help i have tried my best. I really need your help. So im trying to make a mark order as complete. Now it all works up to the button to mark order as complete. I ran a migration to add. class AddCompleteToOrder < ActiveRecord::Migration def change add_column :orders, :complete, :boolean, default: false end end Then i added a method the order.rb of def complete! update(complete: true) end Then routes.rb resources :orders do post "complete", to: "orders#complete", on: :member end Then this is the button = button_to "Mark as complete", {

opsworks rails.env does not match custom json rails_env

匿名 (未验证) 提交于 2019-12-03 09:18:39
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In my Nginx/Unicorn Opsworks environment i've set our custom JSON rails_env attribute to "opsworks" { "deploy": { "myapp": { "rails_env": "opsworks" } } But when I go into the Rails console and run Rail.env Rails returns "development". Opsworks is starting Unicorn under the opsworks environment but Rails seems to be running in development. The log directory contains logs for both development and opsworks. Any thoughts on what i'm doing wrong? 回答1: What you are doing is setting up RAILS_ENV for your rails application. You can view the source

rails virtual attributes won't read from form_for submission

匿名 (未验证) 提交于 2019-12-03 09:17:17
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to implement a rails tagging model as outlined in Ryan Bate's railscast #167. http://railscasts.com/episodes/167-more-on-virtual-attributes This is a great system to use. However, I cannot get the form to submit the tag_names to the controller. The definition for tag_names is : def tag_names @tag_names || tags . map (&: name ). join ( ' ' ) end Unfortunately, @tag_names never gets assigned on form submission in my case. I cannot figure out why. SO it always defaults to tags.map(&:name).join(' '). This means that I can't

Fetch a Rails ActiveRecord &#039;datetime&#039; attribute as a DateTime object

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an attribute in one of my models that contains a Date/Time value, and is declared using t.datetime :ended_on in my migrations. When I fetch this value using myevent.ended_on , I get a Time object. The problem is that when I try to use this attribute as an axis in a Flotilla chart, it doesn't work properly because Flotilla only recognizes dates as Date or DateTime objects. I thought about writing a virtual attribute that will convert the existing Time value to a DateTime, but I'm wary of doing this, since I've heard that Time can't