ruby-on-rails

How to setup default attributes in a ruby model

I have a model User and when I create one, I want to pragmatically setup some API keys and what not, specifically: @user.apikey = Digest::MD5.hexdigest(BCrypt::Password.create("jibberish").to_s) I want to be able to run User.create!(:email=>"[email protected]") and have it create a user with a randomly generated API key, and secret. I...

helper function not found in view

I'm following the instructions at: http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids to add the tag cloud to my view: in the controller: class PostController < ApplicationController def tag_cloud @tags = Post.tag_counts end end I also added the tag_cloud method as a helper method in the controller and i...

Ruby ways to authenticate using headers?

I am designing an API system in Ruby-on-Rails, and I want to be able to log queries and authenticate users. However, I do not have a traditional login system, I want to use an APIkey and a signature that users can submit in the HTTP headers in the request. (Similar to how Amazon's services work) Instead of requesting /users/12345/phot...

Get data from html form to ruby in Ruby on Rails

Get data from html form to ruby in Ruby on Rails I have some html like this <html> <h1>Text to PDF</h1> <textarea name="comments" cols="40" rows="5"> Enter your Text here... </textarea><br> <input type="submit" value="Submit" /> </form> </body> </html> I want to give the value of the text into the controller for this page/view. How d...

In MVC framworks (such as Ruby on Rails), does usually Model spell as singular and controller and view spell as plural?

I usually see Ruby on Rails books using script/generate model Story name:string link:string which is a singular Story, while when it is controller script/generate controller Stories index then the Story now is Stories, which is plural. Is this a standard on Ruby on Rails? Is it true in other MVC frameworks too, like CakePHP, Symf...

Rails / Capistrano - How to set a staging server to show development logs in DB

In my development logs, i get information like SQL statements made, etc. However, when i deploy to a staging server, i do not get that in my development logs How do i configure capistrano/rails to get that? NOTE: I need it to be running in production env (database access, etc) ...

When using Bundler and Rails 2.3.5 I get uninitialized constant SubdomainFu when migrating

Hi I'm using bundler with rails 2.3.5 and I'm trying to make sure everything is working correctly but when I do a "rake db:migrate --trace" I get this ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment rake aborted! uninitialized constant SubdomainFu /opt/local/lib/ruby/gems/1.8/gems/activesup...

How do you parse text in Ruby on Rails and add classes to specific parts of it?

I am a Rails novice and I'm creating an application that I'd love some help on. The app is for social reading. It enables a user to highlight a passage from a text then have that passage saved and bolded into the view for later reading by anyone else. I have no problem creating an if statement on whether a certain string of text is in ...

Nowadays, which MVC frameworks (such as Ruby on Rails) are widely in use and also very cool?

Seems like more companies are using Ruby on Rails nowadays. What are some other frameworks that are commonly in use nowadays and some that make you go "wow, this is cool"? ...

Rails- Using a set of functions across the view , controller and model

Hi folks, i have a function that converts an array to a hash which i would like to use across all the model, controller and view files in the rails app. Does this violate some core design principle, or am i missing something really obvious? UPDATE: This is actually a software engineering question. I want to understand why some "conveni...

rails update whole index of a model with one click

hello! i have a store model, this will handle my leaflet and my shoppingcart for my shop. now i d´like to show all items added from an user to his leaflet in the index of store. in the store an user can change the quantity of the choosen items. and now i want to save that the changes of the different quantities in the database with one ...

How to pass -f specdoc option through rake task

I am using rails 2.3.5 .rake spec works fine. This is from spec --help. spec --help -f, --format FORMAT[:WHERE] Specifies what format to use for output. Specify WHERE to tell the formatter where to write the output. All built-in formats expect WHERE to be a ...

Rails routes question. Always find by name and remove /class_name/ from route

I have a Category model and a Product model. Category has_many products and Product belongs_to Category I want my routes to be like this: /:category_type/:category_name/ opens Product#index /:category_type/ opens Category#index / opens Category#index Is there a way to achieve that with resources? I tried with path_prefix but...

An AuthLogic form is giving me incorrect validation errors -- why?

Hi everyone, I set up AuthLogic for Rails according to the AuthLogic example: http://github.com/binarylogic/authlogic_example. I can log on successfully to the system, but when accessing users/new.html.erb to register a new user, the form returns the following validation errors: Email is too short (minimum is 6 characters) Email shoul...

Ruby on Rails: What are Erubis' disadvantages and why isn't it packaged with Rails by default? How to set it up?

I just discovered Erubis, a replacement for the default view renderer for Ruby on Rails. However, from what I can tell from reading about it, it's superior across the board. It is much faster. It has many more options. It can prevent cross site scripting without having to use h. Does this have any disadvantages versus the standard erb ...

Rails: Overriding ActiveRecord association method

Is there a way to override one of the methods provided by an ActiveRecord association? Say for example I have the following typical polymorphic has_many :through association: class Story < ActiveRecord::Base has_many :taggings, :as => :taggable has_many :tags, :through => :taggings, :order => :name end class Tag < ActiveRecor...

In Ruby on Rails, why will story.votes return an empty Array object, but story.votes.create will actually invoke a method of the Vote class?

In Ruby on Rails, say a Story object can "has_many" Vote objects (a story is voted "hot" by many users). So when we do a s = Story.find(:first) s is a Story object, and say s.votes returns [] and s.votes.class returns Array So clearly, s.votes is an empty Array object. At this time, when s.votes.create is called, it act...

session fixation

I am new to web development, and trying to get a hold on security issues. I went through this article on http://guides.rubyonrails.org/security.html these are some of the steps the author has mentioned how an attacker fixes session. The attacker creates a valid session id: He loads the login page of the web application where he wants ...

AuthLogic - how to determine current user id throughout the system?

Hi all, I have set up AuthLogic almost exactly as per the AuthLogic example app at http://github.com/binarylogic/authlogic_example. After someone logs in as User, they can click on links that send them away into the system and away from the users controller. This is an incredibly noob question, but how can I access that User's ID and o...

Why program with php frameworks if it can be done better with rubi on rails, python or java?

Hi, We have discussion in my job place about question (We use 1 of the php frameworks): Why program with php frameworks big web application if it can be done better with rubi on rails, python or java? Please say our opinion thanks ...