ruby-on-rails

Rails Security: redirect if not current_user

I've been using authlogic and it works really well. One thing I've noticed is that as a hacker I could easily type in this address: localhost::3000/users/a_user_that_is_not_me/edit Since the form in the edit form is for @user which is set to current_user and requires an authenticity token, even if I tried to put in details for the othe...

How to handle revisions to a Wiki with ActiveRecord?

I have a model Article, that has_many Revisions. Revisions have a variety of columns storing all the information about the Article. The Article also belongs_to a current_revision, which is the primary key of the Revision that is currently selected. Each Revision is never changed after being created. When a user goes to edit an Articl...

Authlogic authorization equivalent of restful_authentication

Say I have a simple todo app and I want the users to see only their todos. I'm having trouble authorizing with Authlogic. In restful_authentication, I just do def index @post = current_user.posts.find.all end But I'm unable to do that with authlogic. I looked into declarative_authorization, but still can't get it to work. I want th...

Ruby on Rails: how can I store additional data in the session for authlogic

I'm using Authlogic to authenticate users. I understand how to create and use sessions, but want to store an additional id variable in the current_user session created by authlogic. Can I just do something like this: session[:authlogic_sess_name] = @extra_id.id However, I'm not sure what the authlogic session is named though or ho...

Rails updating attribute security: use a callback or attr_accessible?

I've got a website model that requires a user to verify ownership of the website. Thanks to stack overflow, I was able to find the solution for user ownership verification here: http://stackoverflow.com/questions/1842416/validate-website-ownership-in-rails After the model passes the verification test there is a verified attribute that ...

how to model a many to many relationship

Here is the scenario, Articles have many Comments Users can write many Comments for many Articles The comments table contains both user_id article_id as foreign keys My models are set up like so class User < ActiveRecord::Base has_many :comments has_many :articles, :through => :comments class Article < ActiveRecord::Base ha...

Loading more comments using AJAX in Rails

I am currently implementing a blog-like site using Ruby on Rails. Each "Post" has some comments. Currently I only have the latest 5 comments load, but I want to implement a hyperlink that would load the rest of the comments. Unfortunately with my current implementation, all I get is a bunch of junk spit out. Before Comments Posted ...

How do I test ActiveRecord references in Cucumber?

I am trying to create some cucumber features with references to other objects. I am running into some problems when I want to create relationships between objects and run tests on them. I haven't found any samples anywhere else. Let's say I have the following models: class Athlete < ActiveRecord::Base belongs_to :shoe_size validat...

Error after second spec run with rspec and autospec

After installing rspec/ZenTest and running autospec, it runs my specs the first time as expected. After making a change to one of my specs and upon running the second time I get the following results: /usr/bin/ruby1.8 /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec /home/schambers/Projects/notebook/spec/models/user_spec.rb -...

rails test table doesn't exist after reverting migration

Hello, this is a very silly question I think: I just removed a table named person_emails I created a minute ago in a new demo app I created half an hour ago. Then I started testing like just now, when I ran a unit test on an unrelated model called line_item, and I got "ActiveRecord::StatementInvalid: Mysql::Error: Table 'depot_test.perso...

rails has_many relationship (4 models) and how to access in the view

I have 4 models: transac, transac_data, item, dvd_details class Transac < ActiveRecord::Base has_many :transac_datas has_many :items, :through => :transaction_datas end class TransactionData < ActiveRecord::Base belongs_to :item belongs_to :transaction end class Item < ActiveRecord::Base has_many :transaction_datas has...

Basic Facebooker plugin usage

Can anyone direct me to a resource for getting up and running with the Facebooker plugin? The tutorial linked at the docs barely covers getting an app running, not actually using the API, the docs themselves are basically empty, and I can't find any references to basic API methods around the web, and those that I do find seem already ou...

Rails Model Validation on :symbol for a date

I'm trying to compare a couple of dates from my form. Im my validation I have something like: :mydate - 1.day But I get: undefined method `-' for :mydate:Symbol" Totally a newb question, but I cant figure it out LOL - how do I perform date math on a symbol? Edit: OK, so I cant access the params from the controller either, or th...

Rails Locally Installing Rails Application rake db:migrate returns

I have a private Rails app that I'm trying to install locally. It's currently running in a hosting environment but I'd like to install it locally to begin making changes. I've already worked out that I can make deploy updates to the 'live' server but a recent misstep 'reinforced the need to make changes locally'. After a fair amount of...

How to tell in Rails controller whether user used back button

I need to check in a rails controller whether the user used the back button to come back to the page. Is there a specific method for this? ...

Nested Rails forms and using label_tag, checkbox_tag and other form_tag functions

In regular forms in Ruby on Rails, if using form_for to build a model, as the API docs state, form_for doesn't create an exclusive scope, and it's possible to use form_tag functions within the form_for form. For example: <% form_for :person, @person, :url => { :action => "update" } do |f| %> First name: <%= f.text_field :first_name %...

Best way to do this RESTfully and right : Ruby on Rails

This is probably easy but I'm a bit of a newbie on wrapping my head around these things sometimes. Synopsis: I'm trying to make a checklist application that technicians go through and answer questions about what has been completed or done in the field. The technicians then submit this for review. The questions are created, managed, and ...

how update a view every five minutes in rails

Hi, I have a button StartMonitor ,and after user pressing this button, I will start checking current available memory every 5 minutes. That means the view should be updated every 5 minutes to show all the data got so far. I can get the data , but I have no idea how to update the view. What would you recommend?Thanks. ...

Display username after the user logs in using RESTFUL authentication?

Hi, i'm using RESTFUL authentication on a rails application. The signup/login is working fine. I'm trying to display the username (based on what they logged in with) on the 'members' page they are re-directed to. for example, "Welcome back John!" any ideas? thanx ...

What is the difference between url_for methods?

I'm wondering what is the difference between these two methods: ActionView::Helpers::UrlHelper.url_for and ActionController::UrlWriter.url_for? ...