ruby-on-rails

Which authentication method is a better solution ? restful or authlogic ?

I'm building a Rails 3 web application and i wanna choose between restful authentication and authlogic method. Among restful authentication and Authlogic, which one is better, based on the foolproof security , customisable and hackproof ? ...

Finding friends with the same saved show in ActiveRecord (associations/join problem)

My design has Users with Friendships to other Users, and they can all save Shows to a list of SavedShows. Now for an individual show page, I'd like to get a list of the friends for a particular registered user that have the same show saved, but I can't seem to figure out the right query. I thought it would be something like following (3...

For Rails project, should we separate models into sub directories

How should we separate models into sub directories? 100+ tables. For example, for contract, there are app/models/contract/contract.rb app/models/contract/contract_signer.rb class Contract::Contract < ActiveRecord::Base end class Contract::ContractSigner < ActiveRecord::Base end I dislike it!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ...

nested attribute object is created three times instead of one

I have three models, booking, room and travellers. Booking has many rooms room has many travellers Since I'm doing a multi-step wizard booking and rooms gets created first, the travellers are created later in the update action. This is the log for the update action: http://pastie.org/private/it7onlg8bnurqkgv6mptrq And this is the rel...

How to install authlogic in Rails 3 ?

I find that the the config/environment.rb file looks different in Rails version 3.0. Also when i add the line "config.gem "authlogic".To environment.rb file ...

Rails , The variable of controller didn't pass to view

What might cause this? I am using instantruby 2.0 in window and Rails 2.0.2. is it possible that this version did not support this? /app/controllers/say_controller.rb class SayController < ApplicationController def hello @time = Time.now end end app/views/say/hello.html.erb <html> <head> <title>Hello, Rails!</title> </head> <body> <...

session generator not working for Authlogic in Rails 3.Help me out !!

I installed authlogic and created a signup mechanism.And for creating a sign in mechanism I tried to generate the session controlers as below but rails 3 throws error as follows. How do I create the user_session and proceed with authlogic in rails 3 ? :~/work_space/rails_apps/sample_authentication$ rails generate session user_session ...

ActiveRecord variable apart from column fields

I have a table with a user_id field. In find, I created a join on user table to retreive the username as: @question = Question.find(params[:id], :select=>"questions.*, users.username as username",:joins=>" inner join users on users.id = questions.user_id"); I created an instance variable in Question class with name username. But I...

What is the best way to store procedures/code?

Hello, I have a feed reader written in Rails (the logic is bit complex as I am scraping some data) and I am trying to generalize the methods. Here is my current structure - Class Gizmodo def update update logic end end Class Wired def update update logic end end Now I am thinking of structure like this Cl...

Heroku rake db:migrate fails - Missing tasks/rails

I am just diving into Heroku and have hit a bit of a snag. Whenever I attempt to create my database I am getting the following error. $ heroku rake db:migrate rake aborted! no such file to load -- tasks/rails /disk1/home/slugs/274236_54c3556_0822-55414a07-d565-459a-9412-67cc0e995790/mnt/Rakefile:10:in `require' (See full trace by ru...

Rails ActionMailer methods confusion

I implemented an authentication system using authlogic, and have added password reset functionality as per this tutorial http://github.com/rejeep/authlogic-password-reset-tutorial It all works, but I am confused as to why it does.. There is this code.. class User < ActiveRecord::Base def deliver_password_reset_instructions! rese...

Paperclip & Rails Api

I have a photo rails app using paperclip. My model called photo and the request parameter also photo.So when i am trying to upload via curl i use : curl -F "photo[photo]=@/pics/pic.jpg" http://something/photos.xml . That's works fine! How can i change the photo[photo] parameter to "photo" or "media" or something else? How can i change th...

Rails, "Weaker validations," and state machines.

I'm writing a Rails ActiveRecord model that needs a weaker version of validations. Essentially, the flow goes like so: Email is received and parsed by application. (already handled) Input from email is used to create/populate new model instance. (already handled) Model is checked for a series of conditions. (conditions already wr...

Rails3: How to insert a value to a column without user interaction ?

I have post and user model and I have Many(posts) to One(User) association. I want to display only the posts which are created by that user(current user). So somehow I have to inject the currently logged in user's id into the "user_id" foreign key of the post model during creation. I'm using Devise as my authentication system. Any solut...

High-performance Screen Scrape with Ruby on Rails!

I need to get many data and performance is an essential requirement. Do you have any suggestions? Thanks in advance! ...

Rails Devise signup form not accepting custom username field

Hello all, I'm trying to add a username to my devise installation, ala the Railscast episode. I've added the field to my user model, but when I attempt to create a new user with a username, the form action keeps trying to pass a null value to my database, which raises an error. Here's the schema for my User model: create_table "users...

convert array of parameters from form into string

I have a form with a checkboxes: -form_tag filter_path(@page.permalink), :method => 'get' do |f| -ftype.producers.each do |producer| =check_box_tag "producers[]", producer.id, false =label_tag producer.title %br =submit_tag 'Сортувати', :name => nil When I send a request, it sends a hash params with an array of...

Rails/Indexes performance Q - which is faster?

Table has columns: user_id and season_id Which is faster: #If I have a database index on user_id Table.find_all_by_user_id(some_id) or #If I have a database index on user_id and season_id Table.find_all_by_user_id_and_season_id(some_id, another_id) Is a multi-column index always faster? For example, is writing a multi-column index ...

How to change the content of a view page based on current url.

My app has a navigation bar with options:- "create post", "Show posts owned by me", "Show All posts" But of I navigate to the page "show posts owned by me", the navigation bar should no longer display the option "show posts owned by me". Is the any api such as current_url_path so that I can compare current_url_path api's output with...

Making URL routes case-insensitive for Rails

I have a rails route that goes to the #works for "/profile/abc" /profile/:id However, it breaks when the url's id is capitalized #breaks for "/profile/Abc" /profile/:id Anyone knows why? ...