ruby-on-rails-3

Rails how to create chart data for each month between 2 dates?

不打扰是莪最后的温柔 提交于 2019-12-25 02:18:50
问题 In my model I have: def self.chart_data(start, slut) if start.nil? start = 2.weeks.ago end if slut.nil? slut = Date.today end range = start.to_date..(slut.to_date + 1.day) if start.to_date.beginning_of_month.to_s != slut.to_date.beginning_of_month.to_s kliks = count( :group => 'date(month)', :conditions => { :created_at => range } ) # CREATE JSON DATA FOR EACH MONTH - PROBLEM HERE (range).map(&:beginning_of_month).uniq.map(&:to_s).each do |month| { created_at: month, clicks: kliks[month] || 0

AuthLogic UserSessions Controller Returning Nil [closed]

拥有回忆 提交于 2019-12-25 02:18:45
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 6 years ago . I've set up a new Rails app and am using Authlogic for authentication. I can happily CRUD users but there seems to be an issue with User Sessions. Error

Rails 3 devise user registration edit path not working

我只是一个虾纸丫 提交于 2019-12-25 02:16:27
问题 I have a pretty straight forward app with a couple tweaks to Devise. First I created a Registrations controller that class RegistrationsController < Devise::RegistrationsController inherits from Devise. I created this controller so that I could edit users without re-supplying passwords. https://gist.github.com/1514687 I also did this in my routes: devise_for :users, :controllers => { :registrations => "registrations" }` The signup works fine but when I call the following: <p class="edit"><%=

rails duplicate record not rendering new

廉价感情. 提交于 2019-12-25 02:15:51
问题 all I want is duplicate an existing record. It should render new form with populated data and let me 'Create' this new record. def clone @agreement = Agreement.find_by_slug!(params[:id]) @agreement.clone respond_to do |format| format.html { render action: "new", notice: 'Agreement was successfully cloned.' } end end My Model def clone self.dup() self.slug = nil end I get this error: No route matches {:action=>"show", :controller=>"agreements", :format=>nil, :id=>#<Agreement id: 1, date: "2011

Regexp for specific matching of character string

萝らか妹 提交于 2019-12-25 02:12:54
问题 I need a regex to match something like "4f0f30500be4443126002034" and "4f0f30500be4443126002034>4f0f31310be4443126005578" but not like "4f0f30500be4443126002034>4f0f31310be4443126005578>4f0f31310be4443126005579" 回答1: Try: ^[\da-f]{24}(>[\da-f]{24})?$ [\da-f]{24} is exactly 24 characters consisting only of 0-9, a-f. The whole pattern is one such number optionally followed by a > and a second such number. 回答2: I think you want something like: /^[0-9a-f]{24}(>[0-9a-f]{24})?$/ That matches 24

Unitialized constant in model

青春壹個敷衍的年華 提交于 2019-12-25 02:08:09
问题 I have a very simple model using Mongoid. I've added the use of Redcarpet to parse the MD and store it. However during update_attributes it is throwing an exception. Running the model and running the update through rails c works fine. class Post include Mongoid::Document field :contents_markdown field :contents key :title before_create :markdown before_save :markdown protected def markdown if self.contents_markdown self.contents = Redcarpet.new(self.contents_markdown).to_html.html_safe end

How to refactoring when metaprogramming has side effects?

断了今生、忘了曾经 提交于 2019-12-25 02:04:16
问题 I am using Ruby on Rails 3.2.9 and Ruby 1.9.3-p125. After my previous question I ended up that I have an issue on metaprogramming a self-implemented acts_as_customizable plugin since the related code has side effects on other classes than that "acting as customizable". To summarize the issue: the acts_as_customizable method stated for an Article model "internally" (through metaprogramming) adds a customize method to a Comment model and, in order to save time, Rails doesn't load all those

Why Rails fails with: ruby.exe has encountered a problem and needs to close. We are sorry for the inconvenience

徘徊边缘 提交于 2019-12-25 01:56:05
问题 I run a Rails 3 application on Windows XP and it fails sometimes with the following error: This causes the WEBrick server to shutdown. When I start the server again, sometimes the page loads as expected and sometimes it fails again with the same error. I noticed that the error appears when I change one of the JavaScript files that belong to the loaded page. What could be the reason for this ? How could I debug this ? My Ruby version is: ruby 1.9.2p0 (2010-08-18) [i386-mingw32] . 回答1: You need

rails jquery ajax request not executing

…衆ロ難τιáo~ 提交于 2019-12-25 01:49:23
问题 I am implementing an up-voting system on an app I am building very similar to the one here on stackoverflow. When a user clicks upvote or downvote, an ajax request is sent to one of my controllers which them updates a couple of tables. Once that is done, I use the respond_to to routes to a js.erb file that executes jquery to update the user display. However, the jquery is not being executed. When I lick upvote/downvote, the controller code executes properly (I can see it in the rails console)

using autocomplete in app with ransack

Deadly 提交于 2019-12-25 01:48:17
问题 Good day. I hame a controller that uses ransack to find articles by their title. I need field that's used for finding info to use autocomplete. Currently it finds alright, but no autocomplete, could you assist me in that problem and gem https://github.com/crowdint/rails3-jquery-autocomplete-app? Gemfile gem "ransack" gem 'rails3-jquery-autocomplete' gem 'nifty-generators' gem 'jquery-rails', '~> 2.0' in view: <%= search_form_for @q do |f| %> <%= f.label t('.find') %> <%= f.autocomplete_field