I like to determine if a visitor has already submitted a form.
I was thinking of doing a couple of things:
cookie
ipaddress
requiring login (much less desirable since the signup barrier might dissuade visitors)
Is there a ROR gem for this? If so please post a link.
Thanks
How are you intending on saving the data?
If you're planning on putting this into a model, great. Then you can create some form of unique value (I'd probably base it on an MD5 of IP address and user agent), store that in a field, and require it to be unique for each submission.
There probably is a gem for this, but it's pretty simple anyway.
If you're not putting it into a model, I think we need more details of what your intentions are.
This sounds like a great opportunity to use HTML5's local storage engine.
You can store up to ~5MB and it's persistent.
YUI has a good wrapper for it.
http://developer.yahoo.com/yui/storage/
Related
I’m making an app that performs tasks on other sites for you.
Example - my app would login in to your theguardian.com account and check if you have any replies to your comments and perform an action if you do.
I'm wondering how I should store, and read, the login details for the guardian.com in my app? Obviously I want to avoid plain text.
I'm using rails and Postgres, my app is fully SSL.
EDIT:
I'm voting to close the question as it's obviously a bad idea and it looks like people are going to tell me so many times. #jvillian has suggested a gem which will help encrypt properties on a model if I do want to avoid plain text, which may be of use to anyone who stumbles across the question.
Check out attr_encrypted. I haven't used it personally, but it looks like what you're looking for and looks to be an active project.
I'm using devise. I modified the user fields with no problem. I need to access certain users, and modify their info. For example, let's say that the user "pete" should have the field "type" changed to "active". How do I do that? it should be just accessing the database and modify that field, but I can't make it work. I mean, there are tools to modify databases, but what is the rails way to do it?
I don't need a tool or script or modify the code, it's a small database and very few changes. Once I understand this, I may do something more general.
The typical rails way to operate on your data like this is to write custom rake tasks. The great Ryan Bates has a great screencast on the topic as well: http://railscasts.com/episodes/66-custom-rake-tasks.
If you do not want to do that, and the fixes you are making are really small, then you can do them via the rails console. More on that here: http://railsonedge.blogspot.in/2008/05/intro-to-rails-console.html
If you need the actual code of how to do that, it may look like this:
pete = User.find_by_name('pete')
pete.update_attributes(:type, 'active')
I'm using couchrest_model to manage some DBs in Rails. So far, it worked like a charm, but I noticed that if I PUT some data via HTTP request, CouchRest Model doesn't seem to realise that the changes are made, so it wipes off the whole record. Of course, I can see the changes in Futon, but not in Rails. When I enter the console, the previously saved instance is just not there.
Of course, I could use HTTP all the way, but I'd really like to make use of validations and other goodies that are available in ActiveRecord class.
Is there any chance that I can make these two guys work together?
P.S.
If you think/know that this approach will work with any other CouchDB Ruby/Rails gem, please, do tell! =)
I've mentioned CouchRest Model because IMO it's the most up-to-date and advanced gem out there.
I realised that this one was so damn easy, it's just that I was using the wrong tool (apart from being a proper n00b). AFAICT, it's not possible to use CouchRest Model solely to carry out persistent operations on CouchDB backend. All external calls that alter the database record(s) in certain way will somehow "remove" that record from ActiveARecord. Instead, you'd probably like to use CouchPotato, since it supports persistent operations.
I'll be glad to give checkmark if anyone comes up with vaguely better idea that this one.
I am building a website for a client that wants to be able to make edits to things on their website. As such I need a way to allow the client to login to the site to make their changes.
My initial thought was to make an authentication system that relies on a User table in the database that is capped at one and only one user. It seems sort of overkill however to make a database table for just one result, so I was wondering if there were any other approaches or best practices that anyone could point to for building a site with just one user.
You could simply authenticate with a static password that is received from a file(encrypted), if you do not want a db model for that.
However, setting authentication with a gem like Devise is like 10 minutes of work. In order to be more secure(it can be a matter even in single user apps), you can set it up and be fine :)
I would highly recommend you set up authentication. As SpyrosP said it does not take long when you use Devise.
My goal is to allow users of a Rails web app to see all their open sessions on other computers and close/sign out of them remotely. Similar to gmail's "Account activity" page (link found at the bottom of the gmail inbox page).
I can technically achieve this by using the sessions in the database
account_sessions = CGI::Session::ActiveRecordStore::Session.find(:all)
and iterating over them to find sessions corresponding to the current user (the user ID is stored in the session data), and allowing the user to destroy these sessions.
However, this doesn't offer the usual convenience of working with Rails models. I can't easily express a has_many relationship with the user and make use of
current_user.sessions
nor can I easily put an index on user_id since it's in the data part of the session (instead of being its own column).
This approach also may become impractical if the number of sessions grows, since in the above the table is read into memory.
As a solution, I'm thinking of creating my own model which "mirrors" the relevant portions of the session and is created/updated/destroyed to maintain that correspondence.
This isn't a great way to go about it due to data replication and added complexity of code, but I didn't find another way to do it.
So the question is: is this a good way to go about it, or am I missing something?
Thanks in advance!
Fraser
Edit: I should have mentioned that I'm currently using restful-authentication, and would prefer not to switch.
Since authlogic offers a user session model and is easily extendable, you should be able to achieve exactly what you want, if you don't mind to switch to another authentication mechanism.
Edit: This Railscast should give you a pretty good overview.