ruby-on-rails3

Why does rspec redirect not get full route during test?

I'm attempting the following functional test on the controller. I'm using the following RSpec2 Rails 3 Shoudla Mocha Here's the test context "POST on create should be successful" do before(:each) do Model.any_instance.expects(:save).returns(true).once Model.any_instance.stubs(:id).returns(1) post :create, :model => {}...

How to write this MySql query using Rails3 syntax?

SELECT `subscriptions`.*, DATE_ADD(`subscriptions`.created_at, INTERVAL `packages`.validity DAY) as end_date FROM `subscriptions` INNER JOIN `packages` ON `packages`.`id` = `subscriptions`.`package_id` order by end_date; ...

How to send xml or image data from iphone to a rails 3 server ?

Hi guys, I am developing a hybrid app (rails 3 + iPhone) and I want to send a number of large strings and images to a rails 3 server. I want to do a POST method from iPhone. Can someone help me on how to do this ? since in this case there will be no form in the views how should I accept the data ? Thanks in advance ...

Rails 3 Clone ActiveRecord Model with Submodels

Basically I have two chains of models, one holds 'predicted data' and one holds 'actual data'. I would like to copy all predicted data to actual when an actual is created. def init_data employees = Employee.all employees.each do |e| t = e.template ed = t.effective_dates.first if ed and !e.routes routes = ed.routes....

NoMethodError in Users#show

I'm following the rails tutorial @ http://railstutorial.org On chapter 11, I'm having issues with showing microposts from users. Based on the tutorial, the RSPEC test should pass. However, it fails 1) UsersController GET 'show' should show the user's microposts Failure/Error: get :show, :id => @user undefined method `model_name'...

Rails - Find By with 2 fields?

Hello, I have the following in a controller def update @permission = Permission.find_by_user_id(params[:user_id]) But I want it to also find by another param, project_id How can I do something like this in Rails? @permission = Permission.find_by_user_id_and_project_id(params[:user_id],params[:user_id]) Thanks ...

Rails 3 - Using form Params in a controller's Update?

I have the following form: <%=form_for [:project, @permission], :url => { :action => "update" } do |f| %> <% roles = Role.all %> Role: <%= f.collection_select :role_id, roles, :id, :name, :prompt => true %> <%=f.submit "Send Request" %> <%=f.hidden_field :user_id %> <% end %> In my controller I have: def update @permission = P...

Rails 3 - Controller Def Update, is not updating the record & Not erroring?

Here's is my permissions controller for DEF UPDATE: def update @permission = Permission.where(:user_id=> params[:permission][:user_id] ).where(:project_id=> params[:permission][:project_id]).first respond_to do |format| if @permission.update_attributes( params[:role_id] ) format.js { render :layout => false } else...

Weird routing error in Rails 3.0

I've been converting my Rails 2.3.9 application to Rails 3.0 and everything has been going well. I've created a lot of routes with the new system so I feel like I know how to do this. However, I recently got a routing error I can't solve. I have a users resource defined like this: resources :users do member do get 'activate' ...

Text Messages & Ruby on Rails

Is there any way to use text messages to CRUD data in a Rails app? For instance, a user would send a text message to a specific number and the Rails app could use that data in any way. Just wondering if there's a solution out there. ...

An interesting little 500 error

I just tried to deploy to Heroku and got a 500 server error. heroku logs: Started GET "/" for ##.##.###.### at 2010-10-14 17:59:34 -0700 Processing by WelcomeController#index as HTML Rendered welcome/index.html.erb within layouts/index (2.3ms) Completed in 3ms ActionView::Template::Error (can't convert nil into String): 5: <...

Struggling with a complex Rails 3 query (need: user.friends.checkins)

I'm working on a social networking application and am trying to build a complex query that efficiently pulls all of a users' friends' checkins from the database. Basically I need: "user.friends.checkins" I've recreated (in simplified form) the data structure below for reference and included several solutions I've found, however I feel ...

Using hidden fields to host foreign key data for a child record?

Does using a hidden fields on a form allow for the possibility of someone spoofing the data in the hidden fields that are posted back? For instance, in my Rials app I have parent-child structure where I call new_project_task(@project) which hits the tasks controller create action, and on the page I do not want to show a field for the f...

Rails Production server: stylesheets not displaying!

I just switched over from my development database to the production database, and I realized I'm getting a consistent error nomatter what view I try to open. The stylesheets are not loading correctly, despite being in the correct place. Here's some information about the error: View <head> <%= stylesheet_link_tag "global", "home", "htt...

RSpec mock_models don't appear to be working for request specs: Should they?

I'm building an app in rails 3 using rspec 2 for specs. All my specs are working fine, except my request spec (only have one at the moment, as I'm building specs as I work): def mock_account(stubs = {}) @mock_account ||= mock_model(Account, stubs).as_null_object end before (:each) do Account.stub(:find_by_id).with(1) { mock_account...

NoMethodError in Pages#home

I'm working through the railtutorial.org online book for rails 3. I've made it through most of chapter 11, where we add the ability to submit a micropost. After adding the appropriate code, I'm unable to render the page. The following is the error returned: > NoMethodError in Pages#home Showing c:/rails_projects/sample_app/app...

Not Null in "count" or "find" function in rails

I'm trying to find the not null elements in a database @genus_counts = Table.count(:all, :conditions=> {:col1 => params[:gm], :col2 => nil}, :without => {:col3 => nil}) It's not recognising "without" function. I am in doubt to apply it as array value. @genus_counts = Table.count(:all, :conditions=> {:col1 => params[:gm], :col3 != nil...

What just happened to Arel and what do I do with an Arel::SelectManager ?

I'm desperately trying to make sense of Arel, mostly because I hate dealing with SQL; I was doing so well, but I've hit a wall. I've been working in Rails 3.0.0, and I'm trying to make a complex query with some math in it. The real case is rather more complex, but I've simplified a bit. In my example, I have a table with a particular ...

Unexpected line-breaks when sending XML attachments using ActionMailer

My application stores a lot of XML files. A background job periodically sends some of those XML files to a specific mailbox. The mailer code is dead-simple: class MailSender < ActionMailer::Base default :from => AppConfig.mail_from smtp_settings :address => AppConfig.smtp_host, :username => AppConfig.smtp_user...

How to change Rails 3.0's default log path?

I have to change my rail application's default log path because of my company's internal software deployment process: basically my rails app ends up on a read-only location, and I need the log files written in a directory "made for this". With Rails 2.x we used to add some black magic in our FCGI script to force that in when deployed on...