I'm working on a Rails application where I have some a set of two radio buttons where users can click "yes" or "no". The MySQL DB column created by the ActiveRecord migration is a tinyint.
If the user doesn't click either radio button I want MySQL to store NULL. (The column allows NULL.) And when they come back to edit the data, neither...
So I am beginning to work with Rails and I get some of the concepts but am stuck on an important one.
Let's say I have customers which has many jobs and jobs which belongs to customers.
How would I go about creating a new job for a customer?
I can create a link that goes to customers/1/jobs/new and I can grab the customer ID but how d...
Hi,
I have a RoR application and model SomeModel. I have views for this model and I want to know - is there any method to get the view's path? Of course I can use for this model instance
m = SomeModel.new
v = m.class.class_name.pluralize.downcase
It's working, but maybe you know a better way? :)
...
I have an after_find callback in a model, but I need to disable it in a particular controller action e.g.
def index
@people = People.find(:all) # do something here to disable after_find()?
end
def show
@people = People.find(:all) # after_find() should still be called here!
end
What is the best way to do it?
Can I pass somethin...
I would like to create a set of remote specs "specs/remote" that run with the RAILS_ENV = 'remote'. These specs need to use a different database than the model specs. I would make them integration specs if that was easiest.
Ultimately, what is the easiest way change the RAILS_ENV from test and run a group of specs?
...
Hello,
I was wondering if somebody knows an elegant solution to the following:
Suppose I have a table that holds orders, with a bunch of data. So I'm at 1M records, and searches begin to take time. So I want to speed it up by archiving some data that is more than 3 years old - saving it into a table called orders-archive, and then pu...
Ryan Bates' nifty_scaffolding, for example, does this
edit.html.erb
<%= render :partial => 'form' %>
new.html.erb
<%= render :partial => 'form' %>
_form.html.erb
<%= form_for @some_object_defined_in_action %>
That hidden state makes me feel uncomfortable, so I usually like to do this
edit.html.erb
<%= render :partial => 'form...
I noticed the docs have:
<%= item_counter %>
But I have a partial which I want to add a class into on every 6th one, is there an easy way to do this?
...
Hello,
I am trying to generate a controller with all the RESTful actions stubbed. I had read at link text that all I needed to do was to use call the generator with just a controller name I would get just that. So, I ran "script/generate rspec_controller Properties" and I got an empty controller.
Any other suggestions would be great...
I need help, how can I learn this framework?
Here's what I need to know.
Routes, its expected outcome, the prefix/suffix methods associated with every changes made with it.
ActiveRecord, the dynamic generation of methods, the behind the scenes with prefix_ and _suffix methods.
The View, how do I know what prefix/suffix methods can be ...
i am developing a facebook application with rails and the facebooker plugin from my local machine and have problems to set it up.
here is my facebooker.yml file
development:
api_key: myAPIKey
secret_key: mySecretKey
canvas_page_name: http://apps.facebook.com/rafikbennacer/
callback_url: http://207.172.82.237:3000
pretty_erro...
I did this:
[User.first, User.last].to_xml
and got this:
<users type="array">
<user>
<created-at type="datetime">2010-03-16T06:40:51Z</created-at>
<id type="integer">3</id>
<password-hash></password-hash>
<salt></salt>
<updated-at type="datetime">2010-03-16T06:40:51Z</updated-at>
<username nil="true">...
Hi There.
How can I make a sticky form in rails?
Thanks
...
My original question and accepted solution was posted here: http://stackoverflow.com/questions/2483640/rails-association-question. Check that out first.
My follow-up question is this:
I want to return an object that has both the user attributes and the race attributes. That way I can access, for example, the user's name and the faste...
Let's say I have two objects: User and Race.
class User
attr_accessor :first_name
attr_accessor :last_name
end
class Race
attr_accessor :course
attr_accessor :start_time
attr_accessor :end_time
end
Now let's say I create an array of hashes like this:
user_races = races.map{ |race| {:user => race.user, :race => race} }
...
I'm trying put an if statement directly into a select field in rails, with no success.
Here is what I've tried:
<%= f.select (:book_id,{
if @a!=1
"Harry Potter", 1,
end
if @b!=2
"Lord of the Rings", 2,
end
end %>`
Any ideas?
...
I'm following the Getting Started with Rails guide but ran into an issue opening http://localhost:3000
Shell output:
[2010-03-23 19:19:14] ERROR NameError: uninitialized constant ActiveResource::Base
Error in the browser:
Internal Server Error
uninitialized constant ActiveResource::Base
WEBrick/1.3.1 (Ruby/1.8.7/2009-06-12) at local...
hi, guys, can the save method be used to update a record?
person = Person.new
person.save # rails will insert the new record into the database.
however, if i find a record first, modify it and save it. is it the same as performing a update?
person = Person.find(:first, :condition => "id = 1")
person.name = "my_new_name"
person.sa...
I include this simple Rack Middleware in a Rails application:
class Hello
def initialize(app)
@app = app
end
def call(env)
[200, {"Content-Type" => "text/html"}, "Hello"]
end
end
Plug it in inside environment.rb:
...
Dir.glob("#{RAILS_ROOT}/lib/rack_middleware/*.rb").each do |file|
require file
end
Rails::Initial...
I have seed-fu installed on my mac book, no problems.
But I can install it fine on winxp but when I run it, I get:
Don't know how to bulid task db:seed
I checked my installed directory (c:\ruby\libs) and it appears to be there.
Any ideas?
...