In rails application I have two models: Food and Drink.
Both food and drink have a name, which has to be stored in two languages.
How do I better realize translations for theese tables?
First solution I realized was to replace name column with name_en and name_ru.
Another solution is to encode with YAML hash like { :en => 'eng', :ru => ...
Hey guys here is my code (roughly):
books.html.erb
<% @books.each do |book| %>
<% @bookid = book.id %>
<div id="enter_stuff">
<%= render "input", :bookid => @bookid %>
</div>
<%end%>
_input.html.erb
<% @book = Book.find_by_id(@bookid) %>
<strong>your book is: <%=h @book.name %></strong>
create.rjs
page.replace_h...
Hello
i i have different class and controller.
and i need that one instance of model will be available in controller/
now i'm doing something like this:
def method1
inst = @MyClass.new(params)
inst.action
....
def method2
inst = @MyClass.new(params)
inst.action
....
but i want something like this
def method1 ...
I have a web app hosted in a cloud environment which can be expanded to multiple web-nodes to serve higher load.
What I need to do is to catch this situation when we get more and more HTTP requests (assets are stored remotely). How can I do that?
The problem I see from this point of view is that if we have more requests than mongrel cl...
In my rails app, I want to have a sortable list as part of an object creation. The best practice suggested in Railscast adds the acts_as_list plugin and then initiates AJAX calls to update item position. However, AJAX calls won't work on an unsaved model, which is the situation with new.
One solution would be to save the model immediate...
I am trying to build a CMS I can use to host multiple sites. I know I'm going to end up reinventing the wheel a million times with this project, so I'm thinking about extending an existing open source Ruby on Rails CMS to meet my needs.
One of those needs is to be able to run multiple sites, while using only one code-base. That way, whe...
Rails appears to not be loading any fixtures for unit or functional tests. I have a simple 'products.yml' that parses and appears correct:
ruby:
title: Programming Ruby 1.9
description:
Ruby is the fastest growing and most exciting dynamic
language out there. If you need to get working programs
delivered fast, you should...
Hi guys I was wondering if anyone could help me out, I need to clean up this controller as the resulting code to simply update an items quantity if it already exists seems way too complex.
class LineItemsController < ApplicationController
def create
@product = Product.find(params[:product_id])
if LineItem.exists?(:cart_id => ...
Can I use ActionView::Helpers::SanitizeHelper#sanitize on user-entered text that I plan on showing to other users? E.g., will it properly handle all cases described on this site?
Also, the documentation mentions:
Please note that sanitizing
user-provided text does not guarantee
that the resulting markup is valid
(conforming to...
I've been having almost the same issues as Victor Martin (you can see the questions asked here).
I've got declarative authorization working for just about everything that doesn't involve using conditionals. E.g.
has_permission_on :users, :to => [:edit, :update, :destroy] do
if_attribute :user => is { current_user }
end
Are there any ...
Hey guys,
I was wondering how to go about form validation in rails. Specifically, here is what I'm trying to do:
The form lets the user select an item from a drop down menu, and then enter a number along with it. Using RJS, the record instantly shows up in a table below the form. Resetting the form with AJAX isn't a problem.
The issue...
I installed validation_reflection as a gem and out of the box it picked up on my validates_presence_of validations. But it is not picking up on any of the other default rails validations such as validates_format_of.
I know from the documentation that i am supposed to add something like:
config.reflected_validations << :validates_for...
I happened to be working on a Singleton class in ruby and just remembered the way it works in factory_girl. They worked it out so you can use both the long way Factory.create(...) and the short way Factory(...) I thought about it and was curious to see how they made the class Factory also behave like a method.
They simply used Factory...
Here's my model:
class Comment < ActiveRecord::Base
serialize :request_headers
end
But when I try to do @comment.request_headers = request.headers I get a TypeError (can't dump anonymous class Class) exception.
Another way to ask my question: how can I convert request.headers into a Hash? It uses a Hash under the covers so this sho...
Hi,
is it possible to set/read cross-domain cookies in Opera browser? I'm using solution http://bit.ly/c1Tk1i (sorry - in Russian, plz use google translate) and it works fine in any browser except Opera.
...
Partials in XML builder are proving to be non-trivial.
After some initial Google searching, I found the following to work, although it's not 100%
xml.foo do
xml.id(foo.id)
xml.created_at(foo.created_at)
xml.last_updated(foo.updated_at)
foo.bars.each do |bar|
xml << render(:partial => 'bar/_bar', :locals =>...
I want to do a database-side string concatenation in a Rails query, and do it in database-independent way.
SQL-92 specifies double-bar (||) as the concatenation operator. Unfortunately it looks like MS SQL Server doesn't support it; it uses + instead.
I'm guessing that Rails' SQL grammar abstraction has solved the db-specific operator ...
In Symfony i just have to create models with ORM Designer and export it to symfony as a schema.yml and then use a symfony command to create tables, models and forms.
I wonder if there is an equivalent to the RoR so that you dont have to create models manually by hand?
It saves a lot of time using GUI for this kind of tasks and it is le...
I'm referring to http://www.codinghorror.com/blog/2005/10/equipping-our-ascii-armor.html but I'm getting drastically different results.
Does anyone know how to duplicate his blog post examples in Ruby?
...
I have an index view that lists all of the tags for my Entry and Message models. I would like to only show the tags for Entries in this view. I'm using acts-as-taggable-on.
Tags Controller:
def index
@letter = params[:letter].blank? ? 'a' : params[:letter]
@tagged_entries = Tagging.find_all_by_taggable_type('Entry').map(&:taggable)...