ruby-on-rails-3.2

How to validate request parameters in rails 4 like laravel 5?

人盡茶涼 提交于 2019-12-12 15:01:58
问题 I have an action controller to validate params that are coming from view. def duplicate #params to be validated params = params[:group_to_duplicate] #params have to be validated to avoid method 'find' for some reason group = Group.find(params[:id]) #validate to avoid this 'if' if group group.duplicate params notice = 'Some message' else notice = 'Some other message' end redirect_to groups_path, notice: notice end How to validate the request parameters coming from view, like laravel 5 enter

Devise - Timeout not working

倖福魔咒の 提交于 2019-12-12 13:13:16
问题 Devise does not time out a user in the following scenario: A user logs in, closes the tab, and then re-visits the URL in timeout + X minutes. The user is still logged in. Timeouts work properly if the tab is already open, and is refreshed/clicked later. Which means the timeoutable module is working properly for this scenario. Also so far, I've only been able to reproduce this in non localhost environments. This question has also been asked before on the Devise groups, with no answer. Versions

Rails 3 ORDER BY FIELD and last

青春壹個敷衍的年華 提交于 2019-12-12 12:25:54
问题 Hello I have an issue with Rails 3.2 and ordering. When wanting to order a collection by a field, when calling .last ActiveRecord behaves weirdly... >> User.order("FIELD(id, '1')") User Load (0.4ms) SELECT `users`.* FROM `users` ORDER BY FIELD(id, '1') => [] >> User.order("FIELD(id, '1')").first User Load (0.4ms) SELECT `users`.* FROM `users` ORDER BY FIELD(id, '1') LIMIT 1 => nil >> User.order("FIELD(id, '1')").last User Load (0.3ms) SELECT `users`.* FROM `users` ORDER BY FIELD(id DESC, '1')

Add section to form by rendering a partial when link is clicked

给你一囗甜甜゛ 提交于 2019-12-12 11:47:14
问题 UPDATE 3: For anyone who reads this, this is why it wasn't working as expected in update 2 below: Passing a local variable to a partial that is rendered after the view has already loaded If anyone knows how to solve that issue, let me know please. UPDATE 2: I updated the javascript with the quotation marks and it partially works...in the sense that the javascript is now functional and it will cause a string of text to appear on the page when I click the link as long as I have the partial only

How to get content type of a given url inside Javascript?

雨燕双飞 提交于 2019-12-12 09:57:00
问题 I want to know the content type of a given url input by the user inside my Javascript code. Actually, I have a drop-down list (html,csv,xls etc.) and I want to make it so when the user inputs an url, I want to detect the type of the content of the url and based on this type I want to set the value of my drop-down list (html,csv,xls etc.). I know, I can get the content type using Ruby like this : require 'open-uri' str = open('http://example.com') str.content_type #=> "text/html" or, also, I

Rspec, Paperclip, Fabrication, valid object without saving to filesystem

戏子无情 提交于 2019-12-12 09:47:19
问题 I have a rails 3.2 app with paperclip 3.2 and I have a model that has a required paperclip attachment(thumb). How can I create valid objects without having the file saved to the filesystem or S3. What I currently have is below but this saves to the filesystem on each run. Is there a way to have a valid episode without uploading everytime? Model: class Episode include Mongoid::Document include Mongoid::Paperclip has_mongoid_attached_file :thumb validates_attachment_presence :thumb end Spec:

Why is assets:precompile so slow on Heroku?

若如初见. 提交于 2019-12-12 09:42:16
问题 My deployment set up is to have Heroku precompile assets. I want them precompiled so I can send them to a CDN (via asset_sync) and I want that done on Heroku so I don't have any compiled assets in my repo. I set that up using Heroku's guide and that had been working great. I added turbo-sprockets-rails3 for a speed boost. It had all been working fine and then stopped; I can't figure out why. Now when I deploy (without public/assets ) the assets:precompile Rake task times out on Heroku. To see

Rendering partials from a helper method

落花浮王杯 提交于 2019-12-12 09:35:34
问题 Is it possible to render a partial using a helper method where you can also pass local variables from the view in which the helper method is called? For example, when I include this code directly in the view, it renders the partial properly: <%= render :partial => "add_round", :locals => { :f => f } %> Then I moved it to a helper method: def addRound render :partial => "add_round", :locals => { :f => f } end Then I called it from the view again with: <%= addRound %> This did not work with the

Create a drop down list of many links in rails

雨燕双飞 提交于 2019-12-12 09:16:28
问题 I have many links about for example link1, link2, link3, link4 ...link9. I have to add those links in the drop down. I tried with rails select_tag and also with html tag Using html select tag <span class="device_update"> <select> <option value="link1"><%= link_to "link1", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %></option> <option value="link2"><%= link_to "link2", "#",{:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %><

Return records distinct on one column but order by another column

拈花ヽ惹草 提交于 2019-12-12 09:15:41
问题 I am building a Rails 3 app with a pretty standard message model. I would like to return the most recently created message records for each unique conversation_id. It seems like a fairly simple task, but I have not been able to code or find a working solution. Admittedly, I am not super SQL savvy either (as I have gotten by with mainly Active Record queries thus far). Here is what I'm trying to accomplish. Sample messages table: | id | sender_id | receiver_id | conversation_id | subject |