ruby-on-rails

MySQL Install: ERROR: Failed to build gem native extension.

I'm trying to get MySQL installed to the latest version due to some installation going wrong somewhere along the line. I run the command gem install mysql and I receive the following: Building native extensions. This could take a while... ERROR: Error installing mysql: ERROR: Failed to build gem native extension. /S...

Form needs to recalculate order price

I have a form for creation new order. One order can include several products. Each product has a price. Order's price equals to sum of prices of all product, included into it. My form needs to update order's price, as user sets a quantity for each of the products. Ideas ? ...

Using named routes with parameters and form_tag

I'm trying to create a simple search form in Rails, but I think I'm missing something. I have a named route for search: map.search ":first_name/:last_name", :controller => "home", :action => "search" I'm trying to use that in my search form: <% form_tag(search_path, :method => 'get') do %> <%= text_field_tag(:first_name) %> <%= ...

Problem with Ruby on Rails on Windows[msvcrt-ruby18.dll error] - newbie questions

Hi everyone, I have installed Ruby 1.9.1 recently. Everything went fine, I installed the devkit, gems, rails and decided to use RadRails IDE. But, when I typed "ruby script/server" command, I got the error message telling me that msvcrt-ruby18.dll was not found. Still, I was able to run the WEBrick server. I also tried to open "http://lo...

better alternative in letters substitution

Is there any better alternative to this? name.gsub('è','e').gsub('à','a').gsub('ò','o').gsub('ì','i').gsub('ù','u') thanks ...

Many-to-many relationship with the same model in rails?

How can I make a many-to-many relationship with the same model in rails? For example, each post is connected to many posts. ...

how to connect to postgresql using url

I had asked an earlier question which did not get any replies. Basically I get an error invalid database url when I try to do heroku db:push So I figured I can try explicitly providing the database url. so I tried heroku db:push postgres://postgres@localhost/myrailsdb but that gave error: Failed to connect to database: Sequel::...

How to implement a twitter like message appearance?

I'm now developing comment system for my site on Ruby on Rails. I try to make comments to be appeared when user click on SEE MORE button. I see this is not like we do in pagination, so I need your little help guys! When all comments have been displayed, the SEE MORE button should be removed from the page. ...

Can I look at Mailer views without actually sending an e-mail?

I think this may be a common situation… I'm working on a password recovery system for a Rails app that sends a link to the user to trigger a new password form. Pretty standard stuff. On my development server I don't have any mail-sending software enabled or configured (sendmail, SMTP settings, etc.) In config/environments/development.rb...

how to get ID back from a URL in rails

I have a URL like below /pages/edit_product/11 In my action edit_product how can I get the id 11 So that I can do @p = Product.find_by_id(11) ...

how to create new or update if already existing product in rails.

I have an action that saves new procucts like this: @products = Product.new(params[:product]) @products.save I am calling the same action for editing a product as well. But each time I edit...a new product gets created (because of above statements). A while back I had seen some function that will only create a new record if there i...

Hacking Active Record, how do I utilize the attributes method?

The attributes method returns a hash of all the attributes with their names as keys and the values of the attributes as values; I want to utilize this method, creating a new derivative of the update_attributes(attributes) method, lets call it jz_attributes(attributes). Update_attributes does this: def update_attributes(attributes) s...

Subdomains and locally installed Rails app

I can't figure out what I'm overlooking, perhaps it's obvious or lack of understanding. The app I'm working with uses subdomains which on the hosting server work properly. I figured locally installing would kick up some issues around routing, so I read up on making changes to /etc/hosts and using the Ghost gem. Both seem to work fine i...

Best way to send an email upon creation of a new model instance in Rails?

I have an app with the following models: User, Task, and Assignment. Each Assignment belongs_to a User and a Task (or in other words, a Task is assigned to a User via an Assignment). Once a User completes a Task, the Assignment is marked as complete, and the app immediately creates a new Assignment (or in other words, assigns the task t...

Save Current State of Rails App...Reload if making any undesired changes

Hey guys..this is kind of a weird question but I'm making a webapp in rails and I have about half the functionality I'd like to see completed. Now I've been here before but due to misnaming some model and controllers everything went haywire so I just restarted the app since I knew I already did. I'm wondering if I can "save game" wh...

Rails: why am I having trouble accessing this member variable in a controller method?

I am seeing a very strange issue with a simple controller method. Either I am missing something fundamental or I am encountering a bug. My bet is on the former. I have a Thing model with a ThingController. A Thing has two variables, name and display, both strings. ThingController (code below) has a method toggle_display, that toggles...

Ruby on Rails active record syntax to query status updates in a twitter style application

I have a twitter style application whereby a user follows many people. This is achieved using a self-referential association. This all works very nice but my brain has just gone dead while trying to figure out the active record syntax needed to list status updates (posts) from people the user follows ordered by time in a single query. ...

"start with mongrel" doesn't work, but "ruby script/server" works. Why?

In InstantRails: I click Manage Rails Applications, check Shovell, click Start with Mongrel, visit http://localhost:3000, click Submit a new story!, type login information, click login, the Ruby Console Window closes, I can't login and Firefox outputs Connection Restarted. or I click Open Ruby Console Window, type cd Shovell, type rub...

Select n objects randomly with condition in Rails

I have a model called Post, with a column called vote, and it has a big number of posts I want to select n posts randomly that have >=x votes. n is very small compared to the number of posts What is the best way to do this? I've tried a couple of ways that seem to be very inefficient. Thanks ...

ActiveRecord::HasManyThroughAssociationNotFoundError in UserController#welcome

I have a many to many relationship in rails. All database tables are named accordingly and appropriately. All model files are plural and use underscore to seperate words. All naming comventions are followed by ruby and rails standards. I'm using has many through in my models like this: has_many :users, :through => :users_posts #Post...