ruby-on-rails3

Rails 3 LIKE query raises exception when using a double colon and a dot

Hi, In rails 3.0.0, the following query works fine: Author.where("name LIKE :input",{:input => "#{params[:q]}%"}).includes(:books).order('created_at') However, when I input as search string (so containing a double colon followed by a dot): aa:.bb I get the following exception: ActiveRecord::StatementInvalid: SQLite3::SQLExc...

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', ...

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...

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...

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 ...

Current ruby and rails resources (2010)

Can you great and knowledgable programmers please point me to some current and updated Ruby/Rails blogs/sites? I am also looking for an active forum for lively discussions on ruby/rails. I already tried to google for them but as I already mentioned on SO, many of the links on google seem to be to sites that are no longer updated. ...

Overriding a resource route to / (root) in Rails3: not changing the path helper?

Hi, I am quite new to Rails3, I basically created a subscribers scaffolding, I only want my app to respond to new and create actions. So in config/routes.rb I defined: resources :subscribers, :only => [:new, :create] Which works this way GET /subscribers => subscribers#new POST /subscribers => subscribers#create Now I want my a...

How to check a String if it's an ASCII or not?

For example something like: "ASCII".is_ascii? # => true "تجربة".is_ascii? # => false ...

Outputting jSON in a rails app

ok, rails 3 new developer here. I want my jquery to be able to get a json object from the rails 3 application for projects. Here is my controller. def yourprojects @projects = Projects.all(current_user) respond_to do |format| format.html # index.html.erb format.json { render :json => @projects } end end I added the fo...

SASS with Rails 3

Hey, yesterday I`ve got problems with HAML and Rails 3 which resolved themself. Today i wanted to try SASS and its not working. I have renamed my files to file.scss. The GemFile is up to date with gem "haml". There comes an error, because Rails can`t render my css files. Has anyone some ideas to solve this problem? Peter ...

Rails 3 routing based on context

Greetings, I am trying to implement a "context" system similar to the one used by GitHub. For example, a Post may be created belonging either to the User or one of the Companies the User belongs to depending on whether to User is in the "User" context or a context that refers to one of the Companies. As a part of this, I'd like to be a...

jQuery AJAX to Rails 3, In Rails how to get the Varible Passed via Data?

Rails 3 app.... I have the following jQuery which is working: $.ajax({ url: '/navigations/sidenav', data: "urlpath=" + urlpath, success: function(e){ $("#sideNav-container").slideDown("slow"); } }); urlpath can be paths like '/' or '/projects' or '/authors' stuff like that. My question is how do I grab that ur...

Rails 3 - IF a variable contains a part of the URL ?

Hello, i have a variable like /projects/3/blah blah or /projects/3 or just /projects What I'd like to do is have an IF statement in Rails like this: IF urlPath contains /projects proceed Does Rails / Ruby have a method for that? Also, likely it shouldn't have a false positive for something like /books/projects or /authors/mr-projects/...

Rail3 - Smart way to Display Menu & add an Active Style Class?

Given a Rails 3 App with a menu like: <ul> <li>Home</li> <li>Books</li> <li>Pages</li> </ul> What is a smart way in Rails to have the app know the breadcrumb,,, or when to make one of the LIs show as: <li class="active">Books</li> thx ...

How can I store a YAML object in Memcached ? Without a serializations problems.

I'm using gem 'dalli' but the same problem happen with gem memcached-client development.rb config.cache_store = :dalli_store My app controller Rails.cache.write('presidentes', Candidato.by_cargo(:key => "Presidente")) @presidentes = Rails.cache.read('presidentes') If I debug the @presidentes var it returns --- !binary | BAhvOi...

Rack Error with DreamHost, Passenger, and Rails 3.0.0.rc

Background: I have viewed this question as well as this one - sadly, to no avail. Error Message (Passenger): You have already activated rack 1.1.0, but your Gemfile requires rack 1.2.1. Consider using bundle exec. my Gemfile: source 'http://rubygems.org' gem 'rails', '3.0.0.rc' gem 'nifty-generators' gem 'nokogiri' group :after_ini...

Rails 3 Form?, has a TextArea and Rails gives it an ID, but I'll have several on a page

Hello, here is my partial for writing a comment: <div class="commentBox"> <%=form_for [commentable,Comment.new], :remote => true do |f|%> <%=f.text_area :content, :placeholder=>"Write a comment...", :title=>"Write a comment..." %> <%=f.hidden_field :parent_id%> <br /> <%=f.submit "Add comment"%> <...

Rails 3 - How to Link to a User given a user_id

I'm outputting comments on a /books/1 I have the following: <%= comment.user.id%> ---- This gives the correct user_id What I want to do is create: <%= link_to comment.user.fname, XXXXXXXXXXXXXX %> What I don't know what to put for XXXXXXXXXXXXXX that links to /users/1 1 being the id from the comment.user.id Ideas? ...

Rails 3 - time_ago_in_words says "ABOUT 2 hours ago"...

Code: <%="#{time_ago_in_words(comment.created_at)} ago "%> What i'd like is for it not to have "ABOUT" in front of the 2 hours ago, which shows up for hours but not for minutes... Is there another function or a way to remove it without finding and replacing? ...

Rails 3 - Creating a comment and then returning the Partial with JUST the new comment

Here's the flow I have... First, jquery posts the new comment to the server: $.post(this.action,$(this).serialize(),null,'script'); Then in the comments controller: def create @comment = lots of stuff going on here but it works... if @comment.save flash[:notice] = "Successfully created comment." respond_to ...