ruby-on-rails-3.1

ActionController::RoutingError (uninitialized constant User::UsersController) in heroku (but everything works in local)

无人久伴 提交于 2019-12-06 07:21:26
问题 I am trying to run my app in heroku but I get this error when trying to signup or even access devise's login page: ActionController::RoutingError (uninitialized constant User::UsersController) Is this a devise bug or a server setting i missed in heroku? I am running a rails3.1 app in a cedar stack by the way and loading the index page is good, but if I try to login or sign up, it blows. The signup form DOES show, but when I submit, that's when it blows. I checked the logs and it did POST to

How can I tell whether a given Devise user is signed in right now?

本秂侑毒 提交于 2019-12-06 06:08:15
问题 In a Rails app that uses Devise, is there a way to tell if a specific user is signed in right now ? I know about the view helper, user_signed_in? . What I'm looking for is more like: User.all.each do |user| puts user.signed_in? end I see that Devise has added a current_sign_in_at column to users . But that doesn't get set to NULL when the user signs out, so I can't test with that. How can I check whether a user is currently signed in? 回答1: You can add a before_filter to your

Allowing commas in a numerical field

醉酒当歌 提交于 2019-12-06 05:52:59
问题 This is such a dumb question that I feel like I must be missing something simple. I have a form with a quantity field. People keep typing commas when they enter the quantity (for example, they type 12,000 to indicate twelve thousand) so I would like to strip out the commas before saving the quantity ( 12000 in the example) into an integer column in the database. So far I have tried two methods. Overriding the setter method as suggested in this SO question def quantity=(num) num.gsub!(',', '')

missing fingerprints in asset paths

只谈情不闲聊 提交于 2019-12-06 05:07:50
问题 We just deployed a Rails 3.1 app using the new asset pipeline. In Development everything looks fine, but in production all asset-images are missing. When deploying we followed the Ruby on Rails Edge Guide. As an example, a simple code snippet from our app: asset_path "favicon.png", "images" This generates in production: /assets/favicon.png But the fingerprint is missing (and therefore it is a deadlink on production). We already tried it without the "images", with image_tag instead. Nothing is

Ruby on Rails: Multiple Same Input Fields in Same Form

浪尽此生 提交于 2019-12-06 04:58:04
Have a page where there are multiple input fields of the same thing, Posts. Right now, when a user enters in a question for, let's say 3 fields, the only one that saves to the database is the last one. Whereas, it should save all three and give them each it's own post_id. Also; if the user doesn't enter anything in for the other fields, it should not save in the database either. <%= form_for(@post) do |f| %> <%= f.text_field :content %> <%= f.text_field :content %> <%= f.text_field :content %> <% end %> It's failing because what you've got above evaluates to thee html field with the same name

How to select the latest record of each hour in a day

折月煮酒 提交于 2019-12-06 04:48:41
I want to select the latest record of each hour in a given date, based on the datetime column 'reading_on'. I have executed the below query hourly_max = InverterReading .where("DATE(reading_on) = ? AND imei = ?", Date.today, "770000000000126") .group("HOUR(reading_on)") .having("max(HOUR(reading_on))") hourly_max.group_by(&:id).each { |k,v| puts v.last.reading_on } In the above query I am not getting the required result. What is the proper way to select the latest record of each hour in a day. Below is the table structure SELECT HOUR(a.reading_on) As hr, max(a.id),a.reading_on FROM

ruby on rails 3.1 web design

老子叫甜甜 提交于 2019-12-06 04:20:54
May I ask you how to make rails web design more efficient? Is compass plus blueprint the perfect match? Is the current version of compass support rails3.1 Are there any other frameworks that will make rails web deign easier? Thanks Definitely a framework like compass is awesome, it includes a lot of helpers, and provides a good solid base. For form-styling I would recommend using a gem like [formtastic][1], which not only greatly simplifies making forms, but also provides a standard css file. So all needed tags are then known (and can be overwritten if needed). There a few alternatives to

Gmaps4Rails : How to open the Infowindow of the single marker by default when the Google maps is loaded (without clicking on the marker)

前提是你 提交于 2019-12-06 04:18:18
I am using Gmaps4Rails in my rails application for loading google maps. Everything works fine. I have a single marker and I want to keep the infowindow open by default when the google map is loaded (without clicking on the marker). Please help me how to achieve this using Gmaps4Rails gem? I have tried the following snippet of code but it doesn't work. <% content_for :scripts do %> <script type="text/javascript" charset="utf-8"> Gmaps.map.callback = function() { if (Gmaps.map.markers.length == 1) { var marker = Gmaps.map.markers[0]; var infowindow = marker.infowindow; infowindow.open(Gmaps.map

Rails 3 Active Record relation order: Use hash instead of string

半世苍凉 提交于 2019-12-06 04:17:35
问题 To sort a relation in Rails 3, we have to do this: User.where(:activated => true).order('id ASC') But I think this: User.where(:activated => true).order(:id => :asc) would make better sense because the way the field name be escaped should depend on the adapter ( SqlLite vs Mysql vs PostgreSQL ), right? Is there something similar to that? 回答1: As far as I know there's no option for this syntax built into ActiveRecord, but it shouldn't be hard for you to add one. I found the order method

Devise render sign => up/in form partials elsewhere in code

邮差的信 提交于 2019-12-06 03:52:22
问题 I'm just starting with Devise and Rails3. I have the Authenetication down and working and understand the basics. As of now in my Home Controller that represents my Home/Front Page i have two links one that links to Register => sign_up and one that changes depending on login/logout => sign_in/sign_out. However i dont want to redirect my user to login page. Instead i want to display my login form on my front page. So i have seperated the devise/session/new template int to a view and a _form