ruby-on-rails

making POST request in rails with hyperlinks

I need a bunch of links on a page each of which makes a POST to a different controller. But when I use normal links, I get a ActionController::InvalidAuthenticityToken error. I understand this is because of the missing authenticity_token value. But I don't want to use forms to do the POST because I want them to be links and not buttons. ...

Relating two models and accessing them with a single controller in Rails

Background: I am playing around with the feedzirra plugin in a rails app, and I am attempting to utilize both the feed and entry accessors of the parsed feed in a single view. To accomplish this, I have created two models: feed and feed_entry. They are as follows: feed.rb: class Feed < ActiveRecord::Base attr_accessible :title, :ur...

How do I extract a "table" from an array of ActiveRecords in Rails?

I have several similar Models (ContactEmail, ContactLetter, ContactPostalcard). Each instance (record) in, say, ContactEmail, means a specific Email template was sent to a specific Contact. So, each one (e.g. ContactEmail) belongs_to :contact So, in ContactEmail model, there is an attribute ContactEmail.contact_id. Each Contact has a...

Ruby on Rails: Thinking-Sphinx Affecting What is Rendering [railscast help]

I'm trying to get thinking-sphinx working for my project. I'm following this railscast to get it working, but it's not working how it should. In the railscast, Ryan does @articles = Article.search params[:search] for the index method in the controller. When I do this and replace Article.all with Article.search params[:search] when I rel...

How can I get Capybara @javascript tags executing correctly in Cucumber on a Rails 3 project?

I've swapped out Webrat for Capybara on a new Rails 3 project. I ran through Tim Riley's great post on it here ( http://openmonkey.com/articles/2010/04/javascript-testing-with-cucumber-capybara ), and also cloned his repository, executed the example cucumber feature, and saw the browser window fire open. So the whole Cucumber, Capybara, ...

Printing data in erb

How can I print data, usually html, in erb? Sometimes it is just impossible to do everything in the controller, like so print "you are funny" in a red div, with a big structure and print "you are hilarious" in a blue div with simple structure I cannot store them in a variable in the controller n then print it in erb and the <%= %> ...

rails page.replace_html causes the popup of filedownload window

Hi, I intend to use the following code to replace the partial web page called "activitypage", but instead I got a filedownload window with the message "Do you want to save the file or find a program to open". Why? Thanks, render :update do |page| page.replace_html ('activitypage', :partial => 'index') end return ...

ruby on rails create a custom xml

Hi can i create a custom XML after filling a form in Ruby on rails view template. Once i m done with capturing data i dono how to create an XML? Could anyone help What is exactly rxml and can I use it ? ...

Launching System Processes From Rails

I want users to upload pics and then have a background process that converts them to an animated gif. For right now I'd just like to fork a sys process and let a script do the processing. ...

Cucumber newb question..

I am having trouble showing a mock logged in user in cucumber. When a user is logged in they can, make a post. My Errors: (::) failed steps (::) undefined local variable or method `user' for #<Cucumber::Rails::World:0x85974df4> (NameError) ./features/step_definitions/tasklist_steps.rb:25:in `/^that I want to post a link$/' featur...

Rails associations.

I am trying to make a private messaging system, where you send a message to one or more users. Now the messages schema is like user_id, to_id, msg How do i make the associations so that i can get the details of the sender and the recipient? ...

How do I get XAMPP's MySQL and Ruby on Rails work together on my Mac?

I have mysql and apache running through XAMPP on my Mac machine (10.6.4). I usually do PHP development with this setup butnow I want to start out with Ruby on Rails. Unfortunately I cannot get mysql to work with RoR. I start the mysql Server with XAMPP and when I do "rake db:migrate" I get this output:!!! The bundled mysql.rb driver has ...

Singular resources namespaced by its slug (Routing)

Hi, I have the followed Rails 3 routes: Hello::Application.routes.draw do resources :blogs do resources :articles do resources :comments end end end By raking them, we can find: GET /blogs/:blog_id/articles/:article_id/comments(.:format) {:action=>"index", :controller=>"comment...

MySQL defaults vs ruby initialize method

You can initialize a db attribute to a default value in the following two ways - Configure your db to assign a default value to that attribute Use Ruby's initialize method to assign it a value during Object creation (using something like ActiveRecord to talk to your db) Is there a reason to prefer one of the above methods over anothe...

How to debug in Model?

Hi guys, Does anybody know how to debug in rails in the Model? I have a method that is now working and I was trying to check the variable's value in between typing logger.debug val_name that's working in the controllers but not in the models does anyone know why? The model is not inherited from Active Record if it can be the problem....

Reverse Polymorphic Associations

I have a parent object, Post, which has the following children. has_one :link has_one :picture has_one :code These children are mutually exclusive. Is there a way to use polymorphic associations in reverse so that I don't have to have link_id, picture_id, and code_id fields in my Post table? ...

Using Rails with webrat + selenium or only selenium?

Im reading The Rspec book and in that book, they are using webrat with selenium. I wonder if its possible to use selenium directly for integration tests in Rails instead of using it through webrat? What are the pros and cons with each way? ...

Rails: Alter migrations during early development phases

During the very early phases of development in a Rails app, I prefer to modify the migrations files directly to add new columns (fields) to my tables (models) instead of piling up migrations to alter fields and/or do minor changes. Is that possible in Rails? ...

How many use Rspec for controllers and views?

Are there strong reasons for using Rspec for controllers and views too? My views are heavily dependent on Javascript, and as far as I know, Rspec doesn't handle javascript/ajax on views. Also im using Cucumber + Selenium for that. And should I use it for controllers? Isn't it enough to just use Cucumber + Selenium for the application ...

using lambda in find in rails

I have a method that does a paginated find call like.. 1 coll = paginate(:all, lambda {{:conditions => ['status = ? AND expires < ?', 'a', DateTime.now]}}, :select => Constants::POST_FIELDS, :order => 'posts.ratings DESC', :include => [{:poster => :poster_friends}, :category], :per_page => Constants::LISTINGS_PER_PAG...