ruby-on-rails-3

In state_machine, how do I find which events are valid from the current state?

烂漫一生 提交于 2019-12-24 09:57:57
问题 I am using Aaron Pfeifer's state_machine gem in my Rails3 app -- it's nifty. How do get a list of events are legal in the current state? By this, I do not mean my_model.state_path.events which returns all events transitively traceable from the current state -- I want only those that are available in the current state. I'm pretty sure I'm simply overlooking something obvious. 回答1: Aaron himself answered the question on the PluginAWeek:Core group mailing list: Hi - You can see the list of

How can we connect mysql trigger with Ruby on Rails 3?

谁说我不能喝 提交于 2019-12-24 09:57:46
问题 I'm working on a ROR 3 app which uses mysql as the database. Now I want a trigger every time col1 of table1 is updated. But I also want the values of both col1 and col2 of that row in my rails controllers after the trigger is completed ( so as to update an dynamic progress bar ) ... What approach can I follow for this?? 回答1: Please check this manual entry to define a trigger on your table. A trigger will block the trigggering operation until the trigger completes. There is nothing else to do,

How to use SASS, HAML, and CoffeeScript in Rails 3.2.x Engine?

此生再无相见时 提交于 2019-12-24 09:57:33
问题 Currently, I have a Rails 3.2.9 Engine which is using sass-rails . When I generate a controller with a couple actions, the assets are also generated (i.e., javascript and CSS). However, both the Javascript and SASS are *.js and *.css files. They're not CoffeeScript ( *.js.coffee ) or SASS ( *.css.sass ). Any ideas how to get this work? 回答1: Here's a different solution which will use the coffee-rails and sass-rails gems by default - also fixes haml-rails . I added this to the top of my engine

Particular one-to-many relation

ⅰ亾dé卋堺 提交于 2019-12-24 09:51:26
问题 I've got a Rails 3.1 app with a User model and a House model (this is like a group). I've set up a many-to-many relation with join model Membership between those two and there are methods to manages roles of a user in some house in the join model. But my problem is that a User has only one house and not many. So I always have to do user.houses.first to get his house (I've set up a helper house which does that) but the design is not good so I've tried to put has_one :membership and has_one

results from find_by_email executed in function differs from console

雨燕双飞 提交于 2019-12-24 09:48:23
问题 I'm new to Rails and i'm currently learning from tutorials from http://ruby.railstutorial.org/chapters/modeling-and-viewing-users-one#top find_by_email works on console, however, when I execute find_by_email on User.authenticate("test@test.com","testing") I get a nil returned Where have I possibly gone wrong ? Below is part of the codes from my model, User.rb class User < ActiveRecord::Base attr_accessor :password attr_accessible :name, :email, :password, :password_confirmation email_regex =

config.logger and config.paths.log in Rails 3

巧了我就是萌 提交于 2019-12-24 09:48:18
问题 I get this error when trying to start the server. logger.rb:541:in `exist?': can't convert Rails::Paths::Path into String (TypeError) This is the code in my development.rb. require 'log_formatter' config.logger = Logger.new(config.paths.log.first) config.logger.formatter = LogFormatter.new config.logger.level = Logger::DEBUG I have tried adding .to_s, but it's no use. Google is no help either. 回答1: Try config.logger = Logger.new(config.paths.log.first.path) http://api.rubyonrails.org/classes

override to_xml to limit fields returned

旧时模样 提交于 2019-12-24 09:44:49
问题 using ruby 1.9.2 and rails 3, i would like to limit the fields returned when a record is accessed as json or xml (the only two formats allowed). this very useful post introduced me to respond_with and i found somewhere online that a nice way to blanket allow/deny some fields is to override as_json or to_xml for the class and set :only or :except to limit fields. example: class Widget < ActiveRecord::Base def as_json(options={}) super(:except => [:created_at, :updated_at]) end def to_xml

Limit not working as expected in Rails3

◇◆丶佛笑我妖孽 提交于 2019-12-24 09:39:59
问题 I have the following code in my practices controller index method: @practices = @activity.practices.order('created_at DESC').limit(20) Unfortunately, the limit call is not working, and @practices is returning >20 objects. I'm sure this is a simple thing to fix, but I'm not sure what I'm doing wrong. I seem to be using this method in the way prescribed in the docs.. I have tried placing the call to limit before the order call, with the same result. UPDATE SQL LOG: Practice Load (1.6ms) SELECT

Updating nested forms with existing data in inner form using rails 3

…衆ロ難τιáo~ 提交于 2019-12-24 09:36:43
问题 I'm trying to get a nested form view to update properly. This is however causing problems when the second form has existing data. I'm using accepts_nested_attributes_for and nested_form_for. The second which only purpose is to dynamically add the form element using js. See github for more The error I'm getting is: Couldn't find Muscle with ID=3685340 for Exercise with ID=212831413 I've tried to manually do the updating but my code didnt really work and I'm under the impression that it

Heroku assets for Twipsy and Tablesorter not working, locally yes

萝らか妹 提交于 2019-12-24 09:31:06
问题 I was wondering if anyone else ran into the problem where jQuery scripts such as Twipsy (from Twitter bootstrap) and Tablesorter work locally but not on Heroku. Each time I cleaned my public/assets folder and precompiled for deployment environment. The script actually shows up in the precompiled JS on heroku, but it doesn't seem to be recognized.... The weird part is that the first jQuery/Ajax function for the dropdown works fine on Heroku. I use Rails 3.1 on heroku cedar stack Here is my