Say I have a Rails Model called Thing. Thing has a url attribute that can optionally be set to a URL somewhere on the Internet. In view code, I need logic that does the following:
<% if thing.url.blank? %>
<%= link_to('Text', thing_path(thing)) %>
<% else %>
<%= link_to('Text', thing.url) %>
<% end %>
This conditional logic in the vie...
How can I render after executing an action in a restful controller instead of redirecting.
I have a controller with standard actions, and I added a special action that adds data to the resource in question, via a form on the #show page (Think comments on a post). I am validating the input from the form and want to re-render the show act...
I'm an email n00b but I am working on an application that sends HTML email with Unicode characters (as my friend noted "enjoy encoding hell").
The Subject: header comes from user input and therefore may contain Unicode characters. Some mail clients (like GMail and Outlook 2007) are OK with this, but from my reading it seems the right wa...
I see the following code in the attribute_fu plugin:
module AttributeFu
module Associations #:nodoc:
def self.included(base) #:nodoc: ...
Linux 2.6.18-92.el5, ruby 1.8.7, Rails 2.2.2, mysql gem 2.7
I installed the MySQL binary distribution under /usr/local, then installed the mysql gem like this:
gem install mysql --no-rdoc --no-ri \
-- --with-mysql-include=/usr/local/mysql/include \
--with-mysql-lib=/usr/local/mysql/lib \
--with-mysql-config=/usr/local/mysql/bin/m...
Trying to use ActiveRecord::Base.transaction I figured that rollback doesn't work by default using Rails 1.2.6 and mysql 5.0. Playing with it a little bit more I found out that autocommit is not set to 0 in mysql connection.
Questions:
1) how do I disable autocommit in rails for all connections
2) will it have some negative impact on...
I want to pass the params collection from the controller to the model to parse filtering and sorting conditions. Does having a method in the model that takes the params from the controller break MVC?
...
The DB load on my site is getting really high so it is time for me to cache common queries that are being called 1000s of times an hour where the results are not changing.
So for instance on my city model I do the following:
def self.fetch(id)
Rails.cache.fetch("city_#{id}") { City.find(id) }
end
def after_save;
Rails.c...
I am working on a rails application (I have some experience with rails). But, this time I am using RESTful to build it. I am wondering how do I validate my models in a RESTful fashion? What I mean by that is when a user enters data into a form, but the model validations prevent the model from being created what is a RESTful way to red...
I have a staging Rails site up that's running on MySQL 5.0.32-Debian.
On this particular site, all of my tables are using utf8 / utf8_general_ci encoding.
Inside that database, I have some data that looks like so:
mysql> select * from currency_types limit 1,10;
+------+-----------------+---------+
| code | name | symbol |
...
Currently when I want to create a Rails application using edge I first just run...
rails appname
Then I...
rake rails:freeze:edge
Then I delete all of the folders but the vendor folder which contains the frozen edge. Once that's done I run (from the root of the site)...
ruby vendor/rails/railties/bin/rails .
I do it this way rig...
So I'm having a path issue on OS X Leopard. It seems OS X is adding other paths that I'm not stating and it's messing with my path priority. I only have a .bash_login file, I don't have a .bashrc or a .profile file. My .bash_login file is as such:
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
When I run expor...
I'm working on an AJAXy project (Dojo and Rails, if the particulars matter). There are several places where the user should be able to sort, group, and filter results. There are also places where a user fills out a short form and the resulting item gets added to a list on the same page.
The non-AJAXy implementation works fine -- the v...
Instead of just filling out the form in HTML it should also be possible to just send a post request containing the params.. Is it possible to turn off the authenticity token if, for example, the Accept flag is set to 'application/JSON' in the HTTP header?
...
I'm looking to implement a state machine to manage a user moving through a series of steps over an extended period of time (weeks) with emails and then they interact with the app. I've looked at a couple of AASM plugins and forks (it seems like this plugin space has become a bit chaotic) and am curious what people would recommend.
I sa...
My homepage (or welcome page) will consist of data from two models (lets call them authors and posts). I am new to rails and not sure what is the best way to accomplish this.
Should I create a new controller called welcome which gathers data from the authors and posts and then display them in the welcome index view? Or should I have a w...
I've built a nice website system that caters to the needs of a small niche market. I've been selling these websites over the last year by deploying copies of the software using Capistrano to my web server.
It occurs to me that the only difference in these websites is the database, the CSS file, and a small set of images used for the ind...
Environment: Rails 2.2.2, Oracle 10g
Most of the columns declared "date" in my ActiveRecord models are exactly that: dates: they don't care about time at all.
So with a model declared thus:#
class MyDateOnlyModel < ActiveRecord::Migration
def self.up
create_table :my_date_only_model do |t|
t.date :effective_date
t.ti...
I need to format an integer representation of bytes into something friendly, and I'm hoping that there's a utility function in Ruby or in Rails that will do that formatting for me (to perpetuate my laziness, of course.)
I'm looking for something that would look like:
format_bytes(1024) -> "1 KB"
format_bytes(102400) -> "1 MB"
L...
I have found the before_dispatch and after_dispatch in dispatcher.rb but I need to access something earlier. Like around when Rails.public_path is defined.
...