ruby-on-rails3

Using Devise with Rails 3. Adding multiple roles?

We are using the devise gem for authentication in a Rails 3 application. We have multiple roles and from the devise stand-point, the roles will differ in terms of confirmation, activation and remember me functionality. The devise documentation has examples of two scopes being defined. One is the User itself and the other one is the admi...

Nested form has_many model. How to get id from nested item?

I've got a nested form, structured: Question has_many Answers. So, the questions are multiple choice. Current form view: - semantic_form_for @question do |f| = f.error_messages - f.inputs do = f.input :question = f.semantic_fields_for :answers do |builder| = builder.input :content, :label => "Answer", :input_html => {...

rails, How to build table in helper using content_tag?

Hi! I defined function in application helper: def display_standard_table(columns, collection = {}) content_tag :table do concat content_tag :thead do content_tag :tr do concat columns.collect { |column| content_tag(:td, column[:display_name]) } end end concat content_tag :tbody do ...

Cucumber+Devise routing error

having trouble with testing devise sign up on Cucumber. After "Sign Up" click it shows uninitialized constant User::ArticlesController (ActionController::RoutingError) I suppose that's because right after Sign up, devise redirects logged user to Articles page and but it's not under namespace User. Because I test user it put everything u...

What is the Rails Way to iterate through multi-step associations in a view?

I have a Rails 3 project with Product. :product has_many :product_properties :product has_many :properties, :through => :product_properties :product_property belongs_to :product :product_property belongs_to :property :property has_many :product_properties :property belongs_to :property_type There is a attribute "sequence" on :proper...

Authlogic, Namespace and private methods in ApplicationController

Hello, I am troubleshooting why my ApplicationController's methods don't seem to work in my namespaced admin area and it seems like when I'm in a namespace I cannot access my ApplicationController's private methods, is this right? If it is like that, what's the best practise to reuse something like Authlogic's example ApplicationContro...

clever universal form partials in rails

I have a widget for currencies which I use throughout my application. Ie. the user changes the currency from EUR -> USD, or about 13 other currencies. I have a few other use-cases such as dates but this one is the easiest to explain. Currency basically just updates a session variable by calling the currency controller and then uses so...

How make this function html_safe?

Hi! I'm writing helper to render html table header def display_standard_table(columns) content_tag :table do content_tag :thead do content_tag :tr do concat columns.collect { |column| content_tag(:th, 'Header'.html_safe) } end end end end The html output is escaped: <table><thead><tr>&lt;th&gt;Header&...

What is the Rails Way to manage a series of has_many relationships off the same model

I am using Rails 3. The main model is Product :product has_many :images :product has_many :related_products (self-referential) :product has_many :descriptions :product has_many :specifications :product has_many :upc_codes :product has_many :prices You get the idea. I'm trying to determine if I can shoehorn this into a properties mod...

Is it possble include Nesta CMS into Rails3 application ?

I'd like "to mount" a Nesta CMS app onto a Rails3 app This should be possible couse of being Nesta a Sinatra app, which should be a Rack mountable layer, ... but how would you do it ? Where will you start from ? Does anybody has experiences on this topic ? Suggested docs ? thanks in advance luca ...

What's the reasonable time for generating web page?

Hi there! I'm working on web app (Rails 3 based). And I really don't like the time it takes to generate the page - depending on the displayed data it takes up to 2.5 and even 4 seconds. So I just was wondering what is the average reasonable time for generating page in your apps. Saying you check the generation time, e.g. it's 750ms and...

Should there be a "ruby" directory under "vendor" in a Rails 3 project?

Is it normal to have the following directory structure under "vendor" in a Rail 3 project? /vendor/ruby/1.8/bin /vendor/ruby/1.8/cache /vendor/ruby/1.8/doc /vendor/ruby/1.8/gems /vendor/ruby/1.8/specifications When I delete the "ruby" directory, and run "bundle update", the whole structure is recreated. "gem env" yields noth...

Where should I put external web service processing logic in Rails?

In my rails application I use some external web services: twitter, google picasa, flickr etc. Where should I put code related to processing responses of these services? ...

rails 3 routing question.

This is probably quite simple, but how can I make a params optional? resources :places match 'register/:id' => 'places#new', :as => :register currently... it breaks if the :id is not passed which most of the time it won't be. <%= link_to "Place Sign Up", register_path %> ...

How To: Delete Migration Files in Rails 3

I would like to remove/delete a migration file. How would I go about doing that? I now there are similar questions on here but as an update, is there a better way than doing script/destroy? Also, should I do a db:reset or db:drop if I remove/delete a migration? Thanks in advance. ...

Plugin to extend actioncontroller for rails

Hi, I am writing my first ever plugin for rails. The plugin is supposed to extend the actioncontroller::base so after going through the tutorials here is what i did... # Foo class << ActionController::Base def function_name assuming the plugin is called foo... but when i call function_name from an action, nothing happens... It see...

Rails 3 Multi Model Form with Multiple new instances of submodel

Hi, I have three models presented in a multi-model form. class Parent < ActiveRecord::Base has_many :children accepts_nested_attributes_for :children end class Child < ActiveRecord::Base belongs_to :parent has_many :other_children accepts_nested_attributes_for :other_children end class OtherChild < ActiveRecord::Base belon...

f.error_messages in Rails 3.0

Rails 3.0 deprecated f.error_messages and now requires a plugin to work correctly - I however want to learn how to display error messages the (new) native way. I am following the getting started guide, which uses the deprecated method when implementing the comments form. For example: <h2>Add a comment:</h2> <%= form_for([@post, @post.co...

ruby1.9, rails & $SAFE=1

Trying to use $SAFE=1 (just wanted to put some processing in a drb server) make rails unusable: it can't load some paths, data recovered from the DB are tainted, etc. For instance: rails console Loading development environment (Rails 3.0.0) ruby-1.9.2-p0 > $SAFE=1; User.first SecurityError: Insecure operation - file? from .rvm/gems/...

Best practice for adding a Ruby extension methods to Rails 3?

I have an Array extension method I want to use in my Rails 3 project. Where should it live? I have a app/classes where I originally put it (array_extensions.rb), and in my config/application.rb I load the path: config.autoload_paths += %W(#{Rails.root}/app/classes). However, when I drop to rails console the extension is not loaded. I...