ruby-on-rails

Is it okay to store the logged in user in the session in Ruby on Rails?

Hey all, I'm very new to RoR, and am trying to implement a user login system. I've got most of it working, but I'm trying to work out how I refer to the logged in user across many different views/controllers etc. Can I store the user in the session? Or is there a better way to do it? Thanks for reading ...

Rails: find_by, conserving leading whitespaces

Hi, when I do the following def somefunction @texts = A.find_all_by_someid(someid) respond_to do |format| format.xml { render :xml => @texts } end end it gets the string from the db correctly, except if the string has leading whitespaces, it seems they are trimmed. Note: the whitespaces are there in the db...

Rails - How do you dynamically call the request methods "get put destroy etc" at runtime in tests

I'm always writing tests to check my controller restricts people from certain actions depending on their status i.e. logged in, admin? etc Regardless of whether its a get to :index or a puts to :create the code is always the same. I'm trying to refactor this so that i have one method such as should_redirect_unauthenticated_to_login_ac...

How can I make named_scope in Rails return one value instead of an array?

I want to write a named scope to get a record from its id. For example, I have a model called Event, and I want to simulate Event.find(id) with use of named_scope for future flexibility. I used this code in my model: named_scope :from_id, lambda { |id| {:conditions => ['id= ?', id] } } and I call it from my controller like Event.fr...

How can I dynamically call the named route in a :partial in rails?

I have the following partial. It can be called from three different times in a view as follows: <%= render :partial => "contact_event", :collection => @contacts, :locals => {:event => email} %> Second time: <%= render :partial => "contact_event", :collection => @contacts, :locals => {:event => call} %> ...

How can I save a webpage as an image in my rails app?

In my rails app I have a need to save some webpages and display them to the user as images. For example, how would I save www.google.com as an image? ...

validation of special characters

i want to put validation in ruby on rails that my username should not contain special characters like !@#$%^*()_-+=/<>?:'";. Please tell me how can i implement it in my code. ...

Learning Ruby on Rails

Possible Duplicates: How to learn Ruby on Rails as a complete Programming Beginner? How to learn Ruby on Rails (RoR)? I want to learn Rails. Any one help me a useful and easy URL for learning Rails ...

statemachine, conditional transitions

I'm currently using Workflow. class Link < ActiveRecord::Base include Workflow workflow do state :new do event :process, :transitions_to => :checking #checking http_response_code & content_type end state :checking do event :process, :transitions_to => :fetching_links # fetching all links end state :f...

OAuth::Problem (parameter_absent)

Im working with OAuth 0.3.6 and the linkedin gem for a Rails application and I have this issue where OAuth throws an error saying that OAuth::Problem (parameter_absent). The thing is it doesn't throw the error on every occasion its called and the problem is I am unable to reproduce the issue locally to test it. The documentation says th...

How can I use && in if in Ruby on Rails?

I tried the following && conditional for my if statement and I get a "bad range" error: <% if (from_today(contact, call.days) == 0..7) && (show_status(contact, call) == 'no status') %> Why and how can I fix it? The only other way I could do it was to have a second nested if statement and break it apart...not pretty :( ...

What do you use for recurring payments in a Rails Application?

I'm fairly new to rails so I'm definitely not up to speed on the community's best practices, tools, etc. So I figure this may be the best place to ask. What do you use for recurring billing in a rails app? From what I can tell, there are a number of options including rolling my own with ActiveMerchant or using one of the SaaS out there...

"no block given" errors with cache_money

i've inherited a site that in production is generating dozens of "no block given" exceptions every 5 minutes. the top of the stack trace is: vendor/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:42:in `add' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/accessor.rb:33:in `get' vendor/gems/nkallen-cache-money-0.2.5/lib/cas...

Possible to see what actual SQL queries Rails invokes when using console script?

Sometimes I like to pop open the console script that comes with Rails to test small excerpts of code. That code normally involves some more involved ActiveRecord queries. Although not an expert in ActiveRecord, I'm proficient with SQL and want to see what it's translating underneath the hood for efficiency purposes. This will help me ref...

User account design and security...

Before I begin, I am using Ruby on Rails and the Devise gem for user authentication. Hi, I was doing some research about account security and I found a blog post about the topic awhile ago but I can no longer find it again. I read something about when making a login system you should have 1 model for User, this contains a user's usernam...

Rails: Object#id will be deprecated; use Object#object_id

Hi everyone, Very quick question. My server is warning me that line 37 will be deprecated, specifically: #Server error: views/projects/index.html.erb:37: warning: Object#id will be deprecated; use Object#object_id #Views/projects/index.html.erb: 6: <% for project in @projects do %> 36: <%= project.id %> 37: <%= Matching.find_all_by_cu...

Rails view - user enters minutes, we save seconds?

Hi everyone, I have a simple text_field in my form where a user enters a time in minutes, i.e. 60. How can I multiply that number by 60 before saving the form, such that the database stores the number in seconds? Then, how do I reverse that and show the field in minutes on another view? Thank you! ...

Why does Rails screw up timezones when I am editing a resource?

Steps to produce this: prompt>rails test_app prompt>cd test_app prompt>script/generate scaffold date_test my_date:datetime prompt>rake db:migrate now edit your app/views/date_tests/edit.html.erb: <h1>Editing date_test</h1> <% form_for(@date_test) do |f| %> <%= f.error_messages %> <p> RIGHT!<br/> <%= text_field_tag @date_...

What is the difference Between .erb , .rhtml and .html.erb ?

Hi All, What is the difference Between .erb , .rhtml and .html.erb Which is recomanded thanks cheers sameera ...

How do I use XML Builder to create xml in rails?

I am trying the following, but the output XML is badly formed: xml = Builder::XmlMarkup.new({:target => display }) xml.instruct! xml.mail { xml.documents { xml.document { xml.template { xml.source "gallery" xml.name "Postcard: Image fill front" } xml.sections { xml.section { ...