I'm looking for advice on how best to construct a "watch-list" for the app I'm currently working on.
Models as follows:
# user.rb
has_many :items
# item.rb
belongs_to :user
I need to now add a watch-list, where users can favorite certain items, without taking ownership.
I've tried the following:
# user.rb
has_many :items
has_many ...
I want to spec a Sinatra server that receives HTTP requests, stores things in MongoDB, and responds with JSON. How would I spec both the MongoDB entries and the responses?
I'd like to use Cucmber and RSpec to do this cause I hear they're hot, but I'm not really good with them yet.
Thanks!
Matt
...
I've worked through some of the Sinatra and Rails samples, but I'm having a hard time figuring out which features belong to which technology.
What specifically do I gain by using Sinatra/Rails? Is it just ActionPack/ActionView? Correct me if I'm wrong, but I COULD just use Webrick/Mongrel and serve up my .erb files right? And I could us...
Is it possible to detect the last character of string in ruby on rails and replace it by "".
Explanation :: Suppose I have string as "demo-" then i have to check its last character, If it is "-" then replace it by "", otherwise no action should be taken.
Example - Code ::
search_text.downcase! if !search_text.nil?
now if seach_text h...
Ok, so am using the Twitter gem version 0.9.12 and I have successfully figured out how to do the OAuth dance and get the users access token and access secret that I can store securely in the database to send tweets on the users behalf from my rails app.
The problem I am having is that I want to display a message to the user in their ac...
I'm trying to create a set of instances that have different instance names using instance_variable_set to change the instance name and I can't seem to get it to
work.
for i in 0..3 do
username_str = String.new
username_str = 'user_' + i.to_s
username_new = User.new
username_new.instance_variable_set("@#{WHAT_DO_I_PUT...
class User < ActiveRecord::Base
validates_each :name, :email do |model, attr, value|
if value =~ /groucho|harpo|chico/i
model.errors.add(attr, "You can't be serious, #{value}")
end
end
end
Confused as to how this works.
Is :name, email the items it will loop?
...
I've been successfully reading the Linux file '/proc/self/mounts' from within a Ruby thread using stock Ruby in Ubuntu Lucid (ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]). Now I'm trying to do the same on Red Hat 5.5 (ruby 1.8.6 (2010-02-05 patchlevel 399) [x86_64-linux]), but the thread won't complete. I wrote a testing script...
Hi,
I want to build a wizard like multi-step input form for my model.
I want to stick to rest practices as long as possible.
The individual steps in the wizard don't have much inter-dependency so to avoid the round trip to the server, I want to store the whole data on client side using JQueryUI tabs or similar.
I have following ques...
I'm familiar with using Ajax templates to update particular parts of a page, but how do you render with layout when doing so? For example, given a layout:
#foo
= yield :foo
a simple view "show.html.haml":
= render @bar
and a partial:
- content_for :foo
= bar.to_html
... the HTML result would render within the layout and I'd...
I have a two line script that works nicely in ruby. I moved it to haml and getting the error
NameError at /
uninitialized constant Tilt::CompileSite::Nokogiri
the haml code:
%td
- @doc = Nokogiri::XML(File.open(file))
= @doc.xpath("//testsuite").each_with_index {|node,index| "#{index+1}. #{node.attributes["name"]...
I'm trying to add some Markdown styling to my Rails 3 blog application. This should be something simple, but I can't get it to work.
I have kramdown in my Gemfile:
gem 'kramdown'
I ran bundle install. I have an application helper called kramdown
module ApplicationHelper
def kramdown(text)
require 'kramdown'
return Kramdown...
Consider the following string which is a C fragment in a file:
strcat(errbuf,errbuftemp);
I want to replace errbuf (but not errbuftemp) with the prefix G-> plus errbuf. To do that successfully, I check the character after and the character before errbuf to see if it's in a list of approved characters and then I perform the replace.
...
I'm on a Mac running 10.6.4 Snow Leopard, and apparently ruby comes ready to go. But I'm new to Ruby, trying to learn the Rails framework, and so i decided to install the latest version 1.9.2. I followed the instructions here, but after I compile and install, when I run ruby -v I'm still getting 1.8.7. Anyone can help a noob out?
Whe...
Hi.
I don't need to crawl the whole internet, I just need to open a few URL, extract other URL, and then save some page in a way that they can be browsed on the disk later. What library would be appropriate to program that?
...
some case I don't want execute before_update. please help me.
case A: in case I want used before_update
obj = Object.find(id)
obj.save
but case B I don't want used before_update
obj = Object.find(id)
obj.save # in case I want used before_update
...
In Ruby, isn't an instance variable like @foo and a class variable, @@bar?
In some code, I see a few
self.user_name = @name
or even
a += 1 if name != user_name # this time, without the "self."
# and it is the first line of a method so
# it doesn't look like it is a loca...
In Ruby, how can I take an array of tokens representing either integers or ranges and parse them into an array of integers that include each integer and each element in each range?
Example: Given input [ "5", "7-10", "24", "29-31"]
I'd like to produce output [ 5, 7, 8, 9, 10, 24, 29, 30, 31 ]
Thanks.
...
Possible Duplicate:
What does !! mean in ruby?
Hi,
I'm new to Ruby and can't find anywhere description of what "!!" means.
Here's an example:
def signed_in?
!!current_user
end
If this is a double negative, why not to say:
def signed_in?
current_user
end
Please help.
...
I'm trying to add some syntax highlighting to my blog that currently uses RDiscount. I am converting the Markdown to HTML with RDiscount then parsing the HTML code blocks with CodeRay to add syntax highlighting. This is what I have so far:
class Post < ActiveRecord::Base
before_save :render_body
def render_body
self.rendered_bo...