ruby-on-rails3

Rails ActionMailer with SendGrid

Hello, I'm using SendGrid to send emails on Heroku... The problem so far is while it works great on Heroku, on my local host it fails. Right now I have SendGrig install here, config/setup_mail.rb: ActionMailer::Base.smtp_settings = { :address => "smtp.sendgrid.net", :port => "25", :authentication => :plain, :...

Rails 3 ActiveRecord validation based on user permissions

I'm shifting code from an application built in a non-standard custom PHP framework into Ruby on Rails (version 3). In the PHP version all the controllers are really fat, with thin models, which I've always disagreed with, so I'm enjoying the way Rails does validation at the model level, which is probably 90% of what's happening in these...

Ajax call in rails 3

I had a link in the page. I am using jquery to call an action in rails 3. For that i had given <%= link_to "Publish",'',:id=>"view_code#{counter}",:remote=>true %> <%= javascript_tag do %> jQuery(function($) { $("#view_code<%= "#{counter}" %>").click(function() { $.post("/yanas/publish/<%= id %>", function(dat...

Redirect in around filter after action has been yielded

I'm using an around filter which on certain occasions should redirect user to other path AFTER an action has been yielded (either ending with render or redirect). Writing redirect_to in around filter after yield statement results in double render error. Trying to "reconfigure" response object (by setting body to nil and location header ...

How Do I get searchlogic to work with rails 3?

I put searchlogic in my gemfile... and now my rails server won't start :( this is the errormessage gems/ruby-1.8.7-p299/gems/activesupport-3.0.0/lib/active_support/core_ext/module/aliasing.rb:31:in `alias_method': undefined method `merge_joins' for class `Class' (NameError) from /Users/omiohoro/.rvm/gems/ruby-1.8.7-p299/gems/activesup...

RVM, Rails Errors

I installed RVM, then used it to install ruby-1.9.2 and then used rubygems to install rails 3.0. It lets me create a new app but then when I change to the app's root and attempt to generate a scaffold I get this error: Could not find gem 'sqlite3-ruby (>= 0, runtime)' in any of the gem sources. Try running `bundle install`. So then I ...

DateTime with MongoDB/Mongoid and Rails 3 Not Populating

Here is the code in my Model include Mongoid::Document include Mongoid::Timestamps field :message, :type => String field :send_at, :type => DateTime Here is the code for my form partial <%= f.label :send_at %><br /> <%= f.datetime_select :send_at %> But the date and time is never populated. I made sure that Mongo and Mongoi...

Problem using Resque, Rails 3 and Active-Recored

I have this Class which response to perform to be run by "Resque", I have an error at this line recipient.response = response.body wich is undefined method response=' for #<Hash:0x00000003969da0> I think that because the worker and ActiveRecord can't work together. P.S I already loaded my environment and this class placed in lib directo...

Rails 3 ActiveRecord associated collections custom methods

If I have an Auction record, which has many Bids associated with it, out of the box I can do things like: highest_bid = auction.bids.last(:all, :order => :amount) But if I want to make this clearer (since it's used in multiple areas in the code), where would I define the method: highest_bid = auction.bids.highest_bid Is this actual...

Should I use Rails 2.2 vs Rails 3 for learning?

Frustratingly my laptop has Rails 3 on it, although I cannot find much supporting documentation on how to use Rails 3, excepting the API reference. There appears to be a significant amount about regarding rails 2.2. Would you recommend downgrading and learning 2.2 or just plough ahead with 3 and hope for the best? ...

Rails notification messages in Rails 3?

Hi all- I have an application which has achievements that users can earn. I'd like to display these achievements when a user earns them. The system_messages plugin as rec'd here seems to be perfect, but it is not compatible with rails 3. Are there any rails 3 alternatives that would fit the bill, or am I stuck reinventing the wheel? ...

Rail 3: ActiveRecord plugin methods not available from rake

I am using the import_with_load_data_in_file plugin to load large amounts of data quickly. It works fine in console. However, when calling it from a Rake task, I get: undefined method `import_with_load_data_in_file' for #<Class:0x1038cd9e0> That doesn't really make any sense. The plugin is installed, it's included in the model, and ...

Rails3 - Given a Form that allows for Updating/Creating - How Delete/Destroy a record?

I have the following for which allows for creating or updating a record: <%=form_for [:project, @permission], :remote => true do |f| %> ... You can change roles in the form... (This works great for new or existing records) <% end %> Inside the form, I want to provide an option to delete/destroy the permission. So I added: <%= link_t...

link_to_if Why does it show the Link Title if false?

Why does link_to_if show the link title if the condition is false? I'm using it on a DELETE, and if the condition is false, Rails shows delete but it isn't linked. I don't want DELETE to show up if it's false. Is there a setting or another helper for that? Thank you ...

how to run rspec with no observers in rails 3?

I have a rails3 app that has some observers. I can't for the life of me figure out how to turn these off for my rspec tests! ...

Rails 3 Routing Question

Why in Rails 3 do you have to uncomment match ':controller(/:action(/:id(.:format)))' (as seen in this Hello World article) to make the index method of the hello controller be called when you go to http://localhost:3000/hello? Can somebody please explain why we have to do this in Rails 3 but not Rails 2, and is this a normal thing for Ra...

Rails doing a FIND with Conditions?

Hello, In Rails 3, I created a Search Form that does a FIND with conditions in the Models file. @projects = find(:all, :select => 'projects.*', :conditions => ['name = ?', search_name] ).first This works great if a name is provided in the searchform (search_name). Problem is if searc...

How to pass parameteres to liquid methods?

I would like to pass collection of photos to the template and allow the user to select which picture she wants to display. What would be resonable implementation to do this? The best way to select a picture would be by ID, but the user can only access his own pictures in this scenario. Is the custom tag the only way to do this sort of th...

Rails - Adding a Include/JOINs to a query?

Hello, I have the following in my controller to obtain a project's team members: @project = Project.find(params[:project_id]) @teammembers = @project.permissions.includes(:user).joins(:user, :role).select("*") The problem here is that the user's table belongs_to the instance model. And the instance model has a name, which I want in @t...

Perfecting an RSpec macro for controllers

I'm trying to generate an easy macro for a Rails app that uses Devise for authentication. Basically I want to ensure that when a user accesses a page that requires authentication, they're redirected to the login page. So something like this: it_requires_authentication_for :index, :new, :create, :update The desired results here shoul...