had a similar problem to these guys
fixed with...
cd /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.2
sudo find . -perm 0662 -exec chmod 664 {} \;
had a similar problem to these guys
fixed with...
cd /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.2
sudo find . -perm 0662 -exec chmod 664 {} \;
To handle errors globally in your application, add..
There was a global error processing your request.
The final def def local_request? tells rails that it should act the same way in development mode.
To catch errors locally within your form submits do...
rescue
flash[:notice] = "Sorry, something went wrong"
render :action => 'profile'
end
end
Simple process, here we're basically saying if the user has submitted form data (done a POST), then process the code; if not redirect back to the sending page.
If yes then update the User object relevant to the specific user record (found by the id), updating the record with the parameters from the form. Save the record and render the 'success' page.
If we get a problem with saving the record (activerecord), display a message and goto the 'profile' page.
If we get some other error, display the second message and goto the 'profile' page.
On top of this you can enhance it with flash messages and send off an email with the error code, here's one such way.
def log_error(exception) super(exception)
begin
Alert.deliver_errormail(
exception,
clean_backtrace(exception),
@session.instance_variable_get("@data"),
@params,
@request.env)
rescue => e
logger.error(e)
end
end
Adding this makes it send error emails in development mode..
Now create an Mailer object with...
And put this code in your generated alert.rb file
And create a appropriate alert/errormail.rhtml file in your view for the formatted error email...
| Message | <%= @exception.message %> |
| Location | <%= @env['REQUEST_URI'] %> |
| Action | <%= @params.delete('action') %> |
| Controller | <%= @params.delete('controller') %> |
| Query | <%= @env['QUERY_STRING'] %> |
| Method | <%= @env['REQUEST_METHOD'] %> |
| SSL | <%= @env['SERVER_PORT'].to_i == 443 ? "true" : "false" %> |
| Agent | <%= @env['HTTP_USER_AGENT'] %> |
| User id | <%= @session['user'].id %> |
| User name | <%= @session['user'].name %> |
| User email | <%= @session['user'].email %> |
| Registered | <%= @session['user'].created_at %> |
") -%>
<%= key %>
<%= val.to_yaml.to_a.join("
\n") %>
<% end if @params -%><%= key %>
<%= val.to_yaml.to_a.join("
\n") %>
<% end if @session -%>| <%= key %> | <%= val %> |
Now whenever an error happens you'll get an email about it, good for the production environment.
Remember to setup the emailer otherwise no emails will be sent.
By adding this to your environments/production.rb
Or more detailed,
A further note, remember to add an MX record for the domain your using otherwise your site will be blacklisted by anti-spam sites.
An MX record basically tells other sites where they should send emails to, it's like saying where the postman should deliver incoming letters.
Now if your only sending emails you shouldn't need this but as a previous commenter noted, most anti-spam sites blacklist you if your sending and don't have one; regardless of whether you want the site to receive emails or not. Hence you've got to include one.
A simple example is...
Now ok, this is actually telling anti-spammers your using Google Applications to handle your email (which isn't strictly true) but at least it get's them off your back until you setup your own full-blown POSTFIX mail server.
Which is something I'm working on writing an article for.
Expect that in a future posting.
To quickly validate a user's form input via Javascript, try the following...
First add the onsubmit action to your Form Tag, so that when the user clicks the submit button your Javascript function will fire, and more importantly return a value (true=ok, false=bad).
<form action="checkout.php" method="post" onsubmit="return checkform(this);">
Breaking this down, when the user clicks the submit button, the checkform() Javascript function will fire. When this function returns True then the form data will be sent via the Post method to the page 'checkout.php'.
And using 'this' will pass this form to the Javascript function.
Now the Javascript function, add this inside the HEAD portion of your web page.
<script language="JavaScript" type="text/javascript">
<!--
function checkform ( form )
{
if (form.myfield.value == "") {
alert("your error message");
return false ;
}
return true ;
}
//-->
</script>
Really simple when you break it down.
The function will fire when the user clicks the Submit button on the form, when that is done the Form will pass it's contents to this Javascript function, expecting a value returned.
Now the 'checkform' function will check the form field 'myfield'. If it's value is '' blank then it returns false, otherwise the function returns true.
Note the Form will only continue if the function returns a True value.