I've been playing around with the Liquid templating engine this weekend, and I wonder if the following is possible.
Say I have a latest_posts method in a Blog model, which I can pass an integer to to get the latest N posts. Is it possible to use that method in a liquid template?
For example:
class Blog
has_many :posts
def latest...
Hey, I have a bunch of forms for different controllers all on the same page. This is because theres a bunch of models which stack on each other and this is the best way to edit them.
I'm using partials to include each form into the view, passing locals for the object and url params to be used by form_for
The first (top level) form part...
To set up nested resources in Rails, I have seen example routes given like this:
map.resources :players
map.resources :teams, :has_many => :players
By doing this, you can visit teams/1/players and see a list. But it lists all players, not just those that belong to team 1.
How can I list only the resources that are associated with the...
i have this snippet that i want to access from a controller or a model but i dont know what file to put it in
def cost_to_f(string)
string.gsub(/[\$,]/, '').to_f
end
I tried application controller and application helper and no luck on either
any suggestions
...
I'm currently developing an application where I need to implement some sort of way of handling credits which are purchased by users of my application. These credits will then be used to preform certain tasks inside my application such as purchasing hits in mechanical turk. The reason I need to do this is because in the case of mechanic...
I'm attempting to integrate JQuery into Rails 3. I've downloaded the rails.js file from http://github.com/rails/jquery-ujs and have included it in my app. I've also include JQuery.
But when I attempt to do a simple page.replace like so:
render :update do |page|
page.replace_html "my_div", :partial => "my_partial", :locals => {:mylo...
I need to have a many to many relationship for products and categories
so i have
class Category < ActiveRecord::Base
has_many :categorizations
has_many :products, :through => :categorizations
end
class Product < ActiveRecord::Base
has_many :categorizations
has_many :categories, :through => :categorizations
end
the structure ...
I'm trying to order a query using a field which is translated with globalize2. The problem is that since stored in database and in an association I'm having lot of problems.
Doing an include of the translations and ordering by category_translations.name doesn't work.
I tried a default_scope but since it doesn't allow to use lambda or a...
If I have a model Department with columns user_id and group_id
When the action tries to save an entry into this model that already exists, i.e. 1 (user_id), 22 (group_id) already exists, at that time I want to raise a violation. What is the way to do this in rails?
Following is the code I am using to save right now:
if @department.sa...
While trying to install Rails 3, I get the following error:
command run: "sudo gem install rails --pre"
error'd now with:
Successfully installed rails-3.0.0.rc2
1 gem installed
Installing ri documentation for rails-3.0.0.rc2...
File not found: lib
...
Hi,
I've added a subdirectory app/renderers after Railscast #101. The classes in that directory are not getting reloaded by my development server. It's driving me a little bonkers.
I've read everything I could find on forcing it to reload lib and/or plugins but this seems to be a different case since "everything under app should be rel...
Hey guys, when I first begin a rails project, the model user was designed and created. After all the migration part, it successful created the table "users" at postgres.
Well, then after doing some changes during the project, I realized that was missing an attribute/new column at the table.
So what I did was delete the table users from ...
Hi,
Got a rails application that has a form (new action) with a select with an options value range from 1 to 5. When the users selects one of the options I need to use ruby "build" to build a number of objects depending on what the select value is.
So when the user selects 2 in the select box the following code needs to run:
@rooms = ...
I have a rails application (a sass type app), a sales website for it, and a blog that all share the same domain (mysite.com, blog.mysite, app.mysite). I would like to develop these as 3 different rails apps/projects, but then be able to merge them all together into 1 rails application that shares a single database, domain name, and rail...
I have model/controller called notification.
I want to make a new url so that I can access it by:
/notifications/my_new_url?id=4 and have that page go to view my_new_url.html.erb
however, it always keeps going to show method:
This is in my routes.rb
map.resources :notifications
map.connect 'notifications/get',
:co...
I have a one to many relationship with a child form that is nested using a fields_for operation.
I want to use the built in rails error handling to show error messages on the children using the error_message_on method.
Example:
<% form_for @business, :url => {:action => :page, :page => @page}, :html => {:method => :put } do |f|...
ok, so i got
class A < ActiveRecord::Base
has_and_belongs_to_many :cs
and
class Aa < A
end
class Ab < A
belongs_to :b
end
How can I get all As(the base class) of a certain c, with the Abs joined to their bs - in one go?
Currently, I load a certain c, then go c.as, but I cannot manage to get their bs, too...
...
I have a partial that contains this sanitize() code:
<%= sanitize comment.body,
:tags => %w(a b embed i img object p param),
:attributes => %w(allowfullscreen allowscriptaccess href name src type value) %>
I'd like users to be able to embed videos, links, pictures, use italics, bold, etc.
How unsafe is this and if I put this on a liv...
I have never used Prototype before.
But now when I'm using Rails, it seems to me that it doesn't only manipulate the DOM/Ajax but also the language itself.
Example: http://api.prototypejs.org/language/hash/
It was a long time ago I used jQuery, but I recall that the framework didn't have these features right?
Is this a good feature f...
As luck would have it, I am creating a Rails application (2.3.8) in which I need to change where a request is dispatched based on some criteria. Basically, I need a custom dispatcher.
I have looked at using Rack to modify the request, and in certain instances, re-route the request to a different controller that knows that to do with th...