I have a rails application, running in development mode ( with a sqlite database ). The application's purpose is to allow users to upload files through a java client.
If a user wants to upload a folder, all the files inside it will be recursively uploaded. If a user wants to upload a file, the file will be uploaded normally.
Here's t...
Using a restful resource in Rails, I would like to be able to insert a link into my flash hash that the user can click to destroy the object in question. The only problem seems to be that I cannot get the generated link to work with the RESTful controller!
First I tried
link_to "Change your reservation", reservation_path(@existing_res...
I've been working for some months on a program for processing some data, and it's now at a stage where rather than displaying information (stored using ActiveRecord) via the command-line, I'd like to display the processed information via a Rails app.
The first question I'm facing is whether I should have the data processing and the data...
I would like to use a lighter framework than Rails (Sinatra/Ramaze/Camping) but am concerned that by doing so I will not be able to use a lot of shared libraries that have been tailored to Rails in the form of plugins. Is this a major concern or are most of these plugins usable across different Ruby frameworks?
Are there any other poten...
Hey, I just began to learn ruby/rails. At the moment, I try to do an example of a german book "Praxiswissen Ruby on Rails", which is pretty old and written for Ruby on Rails 1. Anyway, I tried to do the examples with Rails 2. Now I have had problem for over a week.
According to the book (Rails 1) I have to write in my controller:
pa...
For some reason, one of my Ruby on Rails classes produces this sort of error everytime I try to call any method on it:
undefined method `create' for Thread:Class
I created this class just like any other, using ./script/generate model Thread, and then migrating it. So why is it acting so strange?
...
In my next rails project I'm going to need blogging functionality. I'm wondering whether anyone has any good suggestions, or should I just roll my own? (Probably not in 15 minutes)
I think the most important feature will be to display code samples elegantly.
...
I have this block of code:
users = Array.new
users << User.find(:all, :conditions => ["email like ?", "%foo%"])
users << User.find(:all, :conditions => ["name like ?", "%bar%"])
users.flatten!
users.uniq!
puts users.to_json :include => [:licenses]
When I run it using script/console, it returns exactly what you would think it should, a...
I am fairly new to Rails and I have never developed a large application. A friend of mine and I are developing two separate applications and we found out we both have a need for a way to generically manage pricing / discount rules.
Scenario:
Say you have a conference registration application and depending on who uses the application, t...
I have a need for a model(?) on my app which basically contains a status of another entity. In the entity I want to store the id of the status, but in my app, the view is talking in terms of a nice word description. For instance, 1=New, 2=Used etc etc.
How can I go about implementing this in the best way that means I can easily set an...
I have a model called Contact which has_one guest like so.
class Contact < ActiveRecord::Base
has_one :guest, :class_name => "Contact", :foreign_key => "guest"
end
In my create view I'm using the select helper method to list all Contacts that can be chosen as a guest like so...
<% form_for(@contact) do |f| %>
<%= f.error_messages...
Hi, I'm attempting to implement nested object forms for my site, using Ryan Daigle's blog post as a guide (http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes). For some reason, the nested form fields don't appear in the view.
class Instruction < ActiveRecord::Base
has_many :steps
accepts_nested_attri...
I have an existing website/application that uses COBOL-CGI where the COBOL app creates the html pages by filling in data using placeholders.
I now want to create a rails site that in addition to using its own db, should also call the external application to retrieve various information.
Can this application still be called using cgi?
I...
How do I group named scopes? For example, I have two models, User and Activity. A user can have many activities.
Activity has two named scopes:
Activity.ordered_by_created_at
Activity.top_20
I want to create a new named scope Activity.recent such that
Activity.recent == Activity.ordered_by_created_at.top_20
That way, I can call re...
I'd to get a person's age from it's birthday. now - birthday / 365 doesnt work, because some year has 366 days. I came up with following code:
now = Date.today
year = now.year - birth_date.year
if (date+year.year) > now
year = year - 1
end
Is there a more rubyish way to calculate age?
...
I have a user and post model:
class User < ActiveRecord::Base
has_many :sent_posts, :class_name => 'Post'
end
class Post < ActiveRecord::Base
belongs_to :user
end
The problem is that in the console, if I do
User.first.sent_posts.empty?
it returns True.
But if I do this in my view
<%= @user.sent_posts.empty? %>
it returns F...
What's the smartest way to have Nokogiri select all content between the start and the stop element (including start-/stop-element)?
Check example code below to understand what I'm looking for:
require 'rubygems'
require 'nokogiri'
value = Nokogiri::HTML.parse(<<-HTML_END)
"<html>
<body>
<p id='para-1'>A</p>
<div clas...
I'm looking to do some ajax form validation with jquery. Everything is in place and I can return my errors in a json object that looks something like this:
errors => {
"first_name": "cannot be blank",
"password": "cannot be blank",
"last_name": "cannot be blank",
"email": "cannot be blank"}
This works fine if I just want to display t...
I have a controller with multiple actions that take :year and :month as
attributes from the URL. I have made a private method check_date to
check the date is valid and check the date is not in the future.
def check_date(year, month)
if month < 1 || month > 12 || year < 2000
flash[:notice] = I18n.t 'archive.invalid_date'
redire...
How to show Number of Views (like : This link/page has been viewed 68 times) in rails?
I sthere any gem or plugin available for it ?
...