Discount Web Design Blog

Just another Web Design Blog

Entries for the ‘Ruby’ Category

invalidate a cookie on password change

I use cookies to manage user sessions in my Rails app. I recently found that when a user changes the password, the cookie does not get invalidated as expected. As you realize, this could be a great threat to security. How should I handle this problem? I want to expire or invalidate a cookie once [...]

query for ActiveRecord relationship

Hi,
My two Model objects are FeatureMaster and Feature,
I need to be able to get the clients value from the Feature table if it exists or it gets the default from FeatureMaster.

SQL Code:

SELECT COALESCE(f.value, fm.value) AS value
  FROM feature_master AS fm
  LEFT OUTER JOIN feature AS f
    ON f.client_id=1
    AND f.feature_master_id = fm.id
 WHERE fm.feature_key [...]

Most Common Ruby Web Server?

Hi All,
I’ve decided to start learning Ruby. I’ve been coding PHP for over 3 years and am after something a little different, hopefully to satisfy me where PHP doesn’t. I’m wondering however, what the most common web server is that you usually find hosting ruby web applications? On PHP for example, Apache is the clear [...]

facebook like button

I am trying to implement facebook like button on my product details page but it’s not fetching the current url, what can I do to make it working. I am using the facebook iframe code.
<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard& amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;he ight=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

current_user object is getting lost

Hello,
I’m working on an app that tracks oil/gas/electricity consumption. Can be seen on http://thetracker.carbontracking.com with login/password as guest/guest
This is all going fine. Now I decide that I also want to log water usage. I see that it’s the exact same as the method for gas, i.e. a meter that logs usage in m3, so I [...]

In Ruby on Rails, how to ensure files include the same javascript file only once?

In Ruby on Rails, if a partial (such as _msgbox.html.erb) need to use Javascript by

Code:
javascript_include_tag :defaults

but then, the page layout or other view may also have that same line, so the same javascript files will be included multiple time?
Is there a way to tell Rails just to include it at most once? kind of [...]

how to set up true/false attribute for model

I have a project model, it has many users through project_members (id, user_id, project_id, leader)
the project_members table leader column is a tinyint(1) column (true/false). How would I set it up so I could do something like the following:
@project = Project.find(id)
@project.leader (this would give me a User object of the person where the leader column is [...]

Instant Rails on Windows always so slow?

Hello,
I’ve been using Instant Rails on two of my computers, and I have noticed that it takes a really, really long time to run ruby commands in the console. Is there anyway to speed this up? I do not have a Mac, but if I install Ubuntu and do my Ruby editing in Ubuntu, will [...]

Problem with entering rails environment with ruby script/console command

Hello,
I’m learning ruby from Patrick Lenz’s "Build your Ruby On Rails Applications". Please help me with the following -
I’m trying to do the following (copy-paste from book)

Quote:

To enter a Rails console, change to your shovell folder, and enter the command
ruby script/console, as shown below. The >> prompt is ready to accept your
commands:
$ cd shovell
$ ruby [...]

Defining Relationships in Ruby

Hello,
Im new to the world of ruby, im currently designing a small clinical information app using ruby, i have designed my tables and relationships by hand but im having some trouble passing it to the rails world, can someone give me a help please?
Thanks
Table Patient,
id_number:string, id_type:string, name:string, common_name:string, address:string, tax_number:string, birth_date:string, sex:string, mobile_phone:string, home_phone:string, work_phone:string, [...]