Rails

Ruby on Rails CSV upload&import - File name too long

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to let admins import contacts via csv files into the database. Therefore I am using the ruby csv library and the following code snippet: if request.post? && params[:file].present? inputFile = params[:file].read CSV.foreach(inputFile) do |row| #save row here end end However in CSV.foreach(inputFile) do |row| I get an "Errno::ENAMETOOLONG - File name too long"-error and the error message shows me that it uses the whole csv file as file name. Does anyone know why it does that? BTW: The csv file is using ',' and '/n' as delimiters. 回答1:

Ruby on rails 4 app does not work in iframe

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How can I embed my rails app into another website via iframe? It works nicely with RoR 3, but not with RoR 4: error! I tried to use verify_authenticity_token and protect_from_forgery options in my controller... seems it's something else (but I'm not sure). upd. Example: http://jsfiddle.net/zP329/ 回答1: This has to do with Rails 4 enabling additional security protocols by default: http://weblog.rubyonrails.org/2013/2/25/Rails-4-0-beta1/ The setting that breaks iFrames on remote sites is X-Frame-Options. By default, this is set to SAMEORIGIN,

Rails syntax error: unexpected keyword_ensure, expecting keyword_end

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: <h1>Get Ready</h1> <% if params[:ballot_position].to_i > 1 %> <p> Voter <%= params[:ballot_position].to_i - 1 %>, go get voter <%= params[:ballot_position] %> and switch places with them. </p> <p> Voter <%= params[:ballot_position] %>, when you are ready, click the button marked "Ready" below. </p> <% @ballot_link = "/vote/#{params[:election_id]}/ballot/#{params[:ballot_position]}" %> <a href="<%= @ballot_link %>" class="btn btn-primary">Ready</a> Above code seems to be resulting in: ready.html.erb:13: syntax error, unexpected keyword_ensure

Rails 5, Heroku with Let's Encrypt SSL - trouble getting setup configured

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to figure out how to use let's encrypt with my rails app on heroku. I've tried several gems which appear to have been designed to help with this process (letsencrypt-plugin)but have removed all of the installation steps those gems recommend because I couldn't get this working. Now, I'm back to trying to make sense of the tutorials set out here: http://collectiveidea.com/blog/archives/2016/01/12/lets-encrypt-with-a-rails-app-on-heroku/ https://medium.com/should-designers-code/how-to-set-up-ssl-with-lets-encrypt-on-heroku

Rails Server will not run

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Typing $ rails server in terminal on mac yields these two errors that I've tried troubleshooting by uninstalling and installing ruby & rails again and get this same error. Typing localhost:3000 on the browser brings a broken webpage meaning rails is not running properly. As a complete beginner, how do i troubleshoot these problems below simply step by step to get rails to run? Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.7.2 Ignoring byebug-8.2.2 because its extensions

Ruby on Rails: Is it possible to use Camel-cased database field and table names?

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The Ruby on Rails convention for database table and field names is snake_case and not CamelCase. However, I have an existing database being used by a PHP application. I would like to write a Rails application that interacts with this database. Is there an easy, "Rails way" to interact with a database using CamelCase database table and field names? 回答1: The short answer is yes but it's not always easier than migrating the old database to a new database. If you want both applications to be able to use the same database though then it is

Rails : Adding an admin role using devise who can see all the users

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need to create an admin role using devise for my app. I've created basic authentication using devise . I have a devise user model in my app but now i need an admin who can show edit and destroy all the users. I tried following the tutorials but none of them helped. I am using rails 3.0.10 and ruby 1.9.2-p290. 回答1: You just define role.rb first by creating migratioin rails g model role name:string then in role.rb class Role has_one:user end And in user model class user belongs_to :role end Insert two roles into DB 1.admin 2.user Then check

Default Date Format in Rails (Need it to be ddmmyyyy)

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been working with a rails form all day and I was just randomly testing it and tried the date 25/12/2009 and it came up with a huge error. It was at this point I realised that rails is set to american date mode (mm/dd/yyyy) instead of the UK style: dd/mm/yyyy. How can I set rails to automatically deal with all dates in dd/mm/yyyy format? 回答1: In your settings file: config/environment.rb" my_date_formats = { :default => '%d/%m/%Y' } ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!(my_date_formats) ActiveSupport:

Rails / Postgres: “must appear in the GROUP BY clause or be used in an aggregate function”

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using this method: def self.lines_price_report(n) Income.group('date(filled_at)').having("date(filled_at) > ?", Date.today - n).sum(:lines_price) end I'm getting this error in Heroku: PG::Error: ERROR: column "incomes.filled_at" must appear in the GROUP BY clause or be used in an aggregate function How can I fix this? Thank you. Executed query: SELECT SUM("incomes"."lines_price") AS sum_lines_price, date(filled_at) AS date_filled_at FROM "incomes" HAVING (date(filled_at) > '2012-12-04') GROUP BY date(filled_at) ORDER BY filled_at ASC

Rails 5 ActionCable is not returning upgrade headers with status 101 Upgrade response

匿名 (未验证) 提交于 2019-12-03 02:31:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: EDIT: Shown at end, found that upgrade headers were actually created. I'm working from the action-cable-example codebase, trying to build a WebSocket app. The "Chatty" application, which depends upon the browser client provided in the app, works fine. But, I am not going to use that client as I need an external IoT connection. As a result, I am trying to implement the ws/wss WebSocket protocols to external non-browser devices and my connection in route.rb is: mount ActionCable.server => '/cable' I've tried several external clients, such as