Hey all,
I am starting to create my sites in Ruby on Rails these days instead of PHP.
I have picked up the language easily but still not 100% confident with associations :)
I have this situation:
User Model
has_and_belongs_to_many :roles
Roles Model
has_and_belongs_to_many :users
Journal Model
has_and_belongs_to_many :roles
...
Hello world!
We have a form to submit ratings for a certain restaurant in a in our views/restaurants/show.html.erb. We only want logged in users to create new ratings. We put
before_filter :login_required, :only => [ :new, :create ]
(but we also tried only ":create") on top of our RatingsController. If we click the submit button after...
I'm internationalizing my app and I've installed the http_accept_language gem on my system I've placed config.gem 'http_accept_language' into my environment.rb file but every time I try to run this code in my controller
request.user_preferred_languages
it complains of no method error.
There are no other instructions on the readme on...
Hi,
I have four models: Customer, QueueRed, QueueBlue, QueueGreen.
The Queue models have a one to many relationship with customers
A customer must always be in a queue
A customer can only be in one queue at a time
A customer can change queues
We must be able to find out the customers current position in their respective queue
In a...
I often use
respond_to do |format|
...
end
in Rails for my Restful actions, but I don't know what the ideal solution is for handling various forms of, say, html responses. For instance, view1 that calls action A might expect back html with a list of widgets wrapped in a UL tag, while view2 expects the same list of widgets wrapped in a...
Hi everyone,
I was hoping I could get feedback on major changes to how a model works in an app that is in production already.
In my case I have a model Record, that has_many PhoneNumbers.
Currently it is a typical has_many belongs_to association with a record having many PhoneNumbers.
Of course, I now have a feature of adding tempora...
I can't get the following SQL query to work quite right in Rails. It runs, but it fails to do the "HAVING row_number = 1" part, so I'm getting all the records, instead of just the first record from each group. A quick description of the query: it is finding hotel deals with various criteria, and in particular, priortizing them being pa...
Everything works fine in development mode, but when I try to start my app in production mode (RAILS_ENV=production script/server) I get the following error:
/opt/ruby1.8/lib/ruby/gems/1.8/gems/searchlogic-2.4.19/lib/searchlogic/named_scopes/conditions.rb:81:in `method_missing': protected method `scope' called for #<Class:0x7f41de524410...
Hi,
This is quite difficult to explain, but here goes. I have a Rails app with students, courses, assignments and grades
In the student show view, there is a list of all of the courses that a student takes, along with the assignments associated with those courses. All assignments which there is a recorded grade for between the student ...
I am exploring an big controller method, with about 10 or so instance variables. Some of them are set in before_filter methods, and some others inside the method itself. I want to inspect them with puts, but dont want to write all of them out example:
puts "var1: #{@var1.inspect}....var15: #{@var15.inspect}"
Is there a generic method ...
I need to setup 301 redirects for my old URL's which have quiet high PR's.
Indexed URL's are in this format:
www.mysite.com/search/find?category[id]=7-Farming
and want to redirect them, using 301, to:
www.mysite.com/categories/find/farming
In the 1st URL 7 is the id of the farming category, in the 2nd URL "farming" is a permalink....
I have a ruby array that looks something like this:
my_array = ['mushroom', 'beef', 'fish', 'chicken', 'tofu', 'lamb']
I want to sort the array so that 'chicken' and 'beef' are the first two items, then the remaining items are sorted alphabetically. How would I go about doing this?
...
Haha..
I'm using Chronic to parse the time users add in the Calendar. Where the code works and implements the right time, the end result is that, IF a user adds a time, then it has no date, and because it has no date, it will not show in results. Any ideas?
def set_dates
unless self.natural_date.blank? || Chronic.parse(self.natural_d...
Hi there,
I'm trying to run the following spec:
describe UsersController, "GET friends" do
it "should call current_user.friends" do
user = mock_model(User)
user.should_receive(:friends)
UsersController.stub!(:current_user).and_return(user)
get :friends
end
end
My controller looks like this
def friends
@f...
This will probably just be a simple problem and I am just blind or an
idiot but I could use some help.
So I am going over some basic guides in Rails, reviewing the basics
and such for an upcoming exam. One of the guides included was the
sort-of-standard getting started guide over at guide.rubyonrails.org.
Here is the link if you need i...
Can I get a users Facebook picture in a Rails app without fully integrating Facebook Connect into Authlogic?
...
Recently, when I tried to explain why Rails is a DSL to an intern at my organisation, I was not able to articulate my reasonings to the effect I would like to. Maybe I do not understand the space well enough to teach the nuances. Redirecting him to Martin Fowler' article or the google ranked one InfoQ or other material has not helped muc...
say I have this on my routes.rb:
resources :accounts
which gives me, among other things:
new_account GET /account/new
I need to generate this (for example) "/account/new#test"
How do you pass the "#test" to new_account_path() ?
...
Hello,
Even though I know that, at least to my knowledge, this is not the default way of doing associations with ActiveRecord I'm looking for help in order to implement an "hibernatish" Polymorphic model.
For instance, consider the following base model:
# Content only has one property named path
class Content < ActiveRecord::Base
se...
I have a site that on only certain occasions (and so far I have only seen this using Safari 4 on Mac) does not load a page correctly, so the underlying HTML code shows up. Have been unable to find any information about this on the net, not sure what could be causing it...
The setup is:
- Rails app
- Phusion Passenger
- Nginx
- html d...