ruby-on-rails

Rails way to check for object existence before display

I want to find a nice way to check my objects before i display them in the view so I wont get errors. This is my controler @user = User.find_by_username(params[:username]) @profile = @user.profile @questions = @user.questions and this is my view <% unless @profile.blank? %><%= link_to 'Edit Profile', :controller => 'profiles', ...

Invisible CSS comments

I have recently begun the practice of using <%# Ruby on Rails comments %> in my html.erb files, as these do not display in the source code that is then viewable by a user. Is there a way of adding comments to .css files that keeps them private from the eyes of devilish onlookers? ...

Accessing a database object (and other important data) in the View

I know it's a bad practice to use database in the view. However, I'm also passing the User object and I wonder how I can make it easy to use. I love the way it works in Ruby On Rails. You just create an @instance_variable in before_filter and call it from the controllers and from the views. You can't do this in ASP.NET MVC though. So I...

Ruby on Rails, MySQL and Snow Leopard

I have working fine my installation of Ruby on Rails on my Snow Leopard. I've tried for several days install MySQL with Ruby on Rails, all I've got when I run: rake db:create is: (in /Users/naikon/RoR/test2) dyld: lazy symbol binding failed: Symbol not found: _mysql_init Referenced from: /Library/Ruby/Gems/1.8/gems/mysql2-0.2.4/ex...

HAML on Rails 3 doesn`t work

Hey there, i have tried to render some files with HAML in Rails 3. But HAMl doesn`t work. My testfiles have the extension .html.haml. In the GEMFile i have written gem 'haml' and executed the bundle install When i call my testapp i become an error like this: Template is missing Missing template posts/index with {:locale=>[:en, :en], :...

Hiding amazon urls when using S3, Rails and Paperclip

I have just set up file uploads to Amazon S3 using Rails 3 and Paperclip. All this works amazingly well and is up and running. There is just one small detail that I would like to sort out. At the moment, the urls are the amazon urls (ie start http://s3.amazonaws.com) and I would like them to begin with my domain. I have already added...

Unescaping inline links in haml

So I'm trying to get a remove link next to the caption in an emails form. However, my rails voodoo is clearly very weak. It escapes the HTML and I can't figure out how to get it to not. Any hints? = f.input :email, :label => "Email " + link_to_remove_fields("[x]", f) [edit] oh and yes, this does the same thing: = f.input :email, :lab...

How to access cookies method in a Rails 3.0 metal class

I have a Rails 3.0 metal class that is in app/controllers directory. class FooMetalController < ActionController::Metal include ActionController::Cookies include ActionController::Helpers::ClassMethods include ActionDispatch::Session::CookieStore def hit unless cookies[:user_id].nil? logger.info("Cookies value is : ...

Ruby on Rails Net::HTTP use_ssl throws 'undefined method'.

Here's my code: sock = Net::HTTP.new(url.host, url.port) sock.use_ssl = true response = sock.start {|http| http.request(req)} here's the error: undefined method `use_ssl=' for #<Net::HTTP www.paypal.com:443 open=false> google is getting me nothing! thanks. ...

Convention of member routes with parameters?

I am trying to create an action (:my_action) route that will allow me to capture the current object :id as well as a :client_id. For new records, the url would look like this: controller/action/new/my_action/:client_id For editing existing records, the url would look like this: controller/action/:id/edit/my_action/:client_id I hav...

Why can't ActiveRecord assign object to association attribute?

I've spent half a working day trying to track this down in AR. Given a model setup like: class Publication < ActiveRecord::Base has_many :subscriptions end class Subscription < ActiveRecord::Base belongs_to :publication belongs_to :user end In controller, @new_subscription = publication.subscriptions.create( user: @current_u...

Rails 3 - Loading a Subnav with Ajax.... Which controller owns a subnav?

Once my Rails 3 app is loaded, a user can click an item which needs to then load a dynamic subnav. My thinking is (since it needs to be dynamic) is onClick to make a jQuery AJAX call to the server and then to inject the HTML response into a DIV on the page... What I'd like your advice on is how/where the subnav logic should live in the...

modal forms using jquery and railse

What's the best option to to a model/overlay type form (to create a post for example) using rails and jquery? I have tried jquery ui dialog/jquery tools overlay etc, but there does not seem to be a good solution to handle.. 1 - Validation errors, i.e. present the form with appropriate inline/flash validation errors 2 - the only way t...

How can I parse this text using regex (ruby)?

http://services.tvrage.com/tools/quickinfo.php?show=Chuck I'm trying to parse that info, for exmaple, get the Airtime, Airtime@Monday at 08:00 pm I want to get what's after "Airtime@" till the end of the line, to just come out with "Monday at 08:00 pm". How can I do this? ...

App structure for roles-based RESTful resources

Is there a consensus best approach to implementing user roles when using RESTful resource routes? Say I have the following resources: User has_many Tickets Event has_many Tickets Ticket belongs_to Person, Event And then further say I have two types of Users: customers and agents. Both will log into the system, but with different r...

[model]_path generator for named route adding parameters in [model] view

Hallo I have a named route: map.notes '/notes/:id/:from_date/:to_date', :controller => "users", :action => "notes", :defaults => { :from_date => nil, :to_date => nil } When I create a path for this route in any other model or when using the route without the additional parameters (/notes/1) i get the expected url generated: notes_pa...

Segmentation Error in Rails

Hi, I am working on Windows XP machine. I have started to create an application in rails but I am getting Segmentation fault error. Below are the ruby & rails version I am using. C:\Ruby>ruby -v ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32] C:\Ruby>rails -v Rails 2.3.8 When ever I run the server, I am getting this error. C...

rails problem with routing and constraints

I have a problem with routing with an id conditioned by a regex constraint. My route is: resources :albums, :constraints => { :id =>/[a-zA-Z\d\.\-\_]+$/ } do get :offline, :on => :member end If I do this: GET /content/v1/albums/:id(.:format) {:action=>"show", :controller=>"content/v1/albums", :id=>/[a-zA-Z\d\.\-\_]+$/ It w...

Rails 3 basic Get JSON with jQuery and output on the page flow question

Rails newbie, thanks for help with this hopefully basic JSON type question.... I have a model Books in my app, which belong_to users. What'd I'd like to learn how to do, is use jQuery to get a JSON object of the books that the user owns. And then use jQuery to list the results out on a div (id=targetdiv). Where I'm not certain, is is ...

"private method `split' called for"....

Ok, so in my rails project. I'm getting this error, any help? class SearchController < ApplicationController require 'rubygems' require 'open-uri' def index @show_info end def do_search @show = params{:search_term} @show = @show["search_term"] @url = "http://services.tvrage.com/tools/quickinfo.php?show=#{@show}" @si...