ruby-on-rails3

Rails 3 widget helper partial

Hi! I ran into a big problem in moving my application to Rails 3. I have a view helper which i call 'WidgetHelper'. It helps to render some partials automatically when i refer to it. For example <%= widget('loginbox', :global => true) %> But it not works correctly. It renders HTML code as I want, but escapes the return value, what is...

arel, how to join

Given class Category < ActiveRecord::Base has_many :products, :order => 'name ASC' end Using the Rails 3 stack, how can I query for all categories that 'have' products? ...

Rails ActiveRecord and array of primitive types

Hi guys, What is the best way to store array of of primitive types using Rails activerecord? For example I've got article model, which has images property. Images property is array of image urls. I don't wont use separate table to store this array. Regards, Alexey Zakharov ...

Rails 3 with mysql problem

Hello, I have updated to rails 3 on my Snow leopard. Previously i use sqlite for development. It's working fine when i rake db:create. Now I'm trying to install mysql on my mac. I downloaded mysql-5.1.50-osx10.6-x86.dmg Installed all three file.(mysql-{version}-osx10.5-x86.pkg, MySQL.prefPane, MySQLStartupItem.pkg) execute this to in...

How do I redirect to a specific action in a different controller in Rails 3?

I'm writing an API; in this API, I have a FruitBasket model which has Fruits. A particular Fruit may belong to more than one FruitBasket at a time. FruitBasket and Fruit are both ActiveRecord objects. If someone performs a GET on /fruit/100/baskets, I want to provide a JSON list of baskets which have that fruit, in the form of basket ID...

Problem creating Rails 3 Engine

I'm working on creating my first Rails 3 engine and I'm currently getting the following error message is a Railtie/Engine and cannot be installed as plugin (RuntimeError) To give you a bit more background I'm not doing the Engine as a gem, but I've place the Engine files in the vendor/plugins folder. I know there is an issue with load...

Rails 3 form_for nested model form

The form_for helper doesn't appear to work in Rails 3. I am trying to to build a form for model and its child model. class Person < ActiveRecord::Base has_one :address end class Address < ActiveRecord::Base belongs_to :person end In earlier versions of rails I would build the form like this: -# Haml - form_for @person do |f| ....

Rails 3 -- Bundler/Capistrano Errors

I have a basic Rails 3 app working locally on my development box, but want to test out deploying early on to make sure everything works. I'm using Capistrano to deploy. When I run cap deploy (after all the other necessary setup), it breaks on this command with this error: [...] * executing 'bundle:install' * executing "bundle install ...

Rails3 Facebook-esque localized language picklist

Other than copying Facebook's SELECT and OPTION elements, is there a Rails-native way of generating a Facebook-esque, localized-language select list? ...

Rails 3, how add a associated record after creating a primary record (Books, Auto Add BookCharacter)

Hello, Rails newbie... trying to understand the right way to do things... In my app users can create a Book ( I have that working) What I want to happen is when a user creates a book, a record is added to the BookCharacters Table, something like (id, book.id, user.id, characterdescription.string.) When the book is created, the user wh...

Given the following User<>Project<>Permissions<>Roles Model, how to obtain a project's team members?

Given the following: class User < AR::B has_many :permissions has_many :projects, :through => :permissions end class Project < AR::B has_many :permissions has_many :users, :through => :permissions end class Role < AR::B has_many :permissions end class Permission < AR::B belongs_to :user belongs_to :project ...

Rails3 ajax callback has empty xhr

I'm seeing some strange behaviour with my Rails3 app. Note that I'm using the jQuery version of rails.js From rails.js starting at line :49 error: function (xhr, status, error) { el.trigger('ajax:failure', [xhr, status, error]); alert('error in: ' + xhr.responseText ); } From my jQuery code to execute after the form. .bin...

Route question regarding Authlogic and Rails 3.0.0

I upgraded an app I am working on from Rails 3.0.0.beta4 to Rails 3.0.0 and hit an unexpected error. I'm using authlogic for authentication, and after the upgrade the route for new user session form started throwing this error. undefined method `user_sessions_path' Ok, I'm using a singular controller name. Not sure what is different be...

Rails 3, How to add an action for Projects

Hello, I have a Project Index View that shows all the projects in an app I want that view to show if the user signed in is a member or not.... In the Project Index View I have: <% if teammember? %> <td>Request to Join</td> <% else %> <td>Already Joined</td> <% end %> Then in the project's controller I h...

Rails, Why a ActiveRecord Query works in a controller but not a Helper?

I have the following line of Rails 3 In the project.rb model this works great: permissions.find_by_project_id(1).role.name However in a projects_helper it errors "undefined method `role' for nil:NilClass": if Permission.find_by_project_id(project_id).role.name.nil? . . Why is that? What I really want is: current_user.permission...

Add Rails Action View Helpers in a Helper

Hi all! Is there a way I can turn this: <%= f.datetime_select :truckleft, :start_year => Date.current.year, :end_year => Date.current.year, :include_blank => true %> into a helper, because I need to use it a lot throughout the form I do however would like the rest to stay in the view file, like the: <%= form_for(@trip) do |f| %> ...

form_for and scopes, rails 3

Hi I have a problem due to scopes and the form_for helper in rails 3. The routes - file looks like this: scope "(/:tab)" do resources :article end The form looks something like this: <%= form_for(@article) %> <%= f.label :title %> <%= f.text_field :title %> etc. <%end%> The tab - attribute is stored in params[:tab], as ...

Rails3: Take controll over generated JSON (to_json with datamapper ORM)

From my Rails 3 app i want a JSON like this: {count:10, pictures:[ {id:1}, ... ] } I tried render( :json => { :count => 10, :pictures => @pictures.to_json(:only=>:id) } ) but in this case, my pictures get escaped ..."pictures":"[{\"id\":2653299}, .... In my old merb app i had the following simple line...

Rails 3 - How to comment in a View?

What is the Rails 3 way to comment out One Line or Multiple lines of code in a View? And so it doesn't show up in the HTML Source ...

Rails 3 devise, current_user is not accessible in a Model ?

Hello, in my project.rb model, I'm trying to create a scope with a dynamic variable: scope :instanceprojects, lambda { where("projects.instance_id = ?", current_user.instance_id) } I get the following error: "undefined local variable or method `current_user' for #" Where in the controller I can access current_user.instance_id.....