Wednesday, 18 September 2013

How to Add Student_ID to Devise Confirmation Email To Be Emailed to User

How to Add Student_ID to Devise Confirmation Email To Be Emailed to User

I have a rails application where a user needs its student_id to access
some features.
The default devise confirmation email is this
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource,
:confirmation_token => @resource.confirmation_token) %></p>
I want to know where the
<%= @email %>
is from ?
I tried adding
<p>Your student id is <%= @student_id %> ! Please don't forget ! </p>
but it did not work.
I have this in my routes
devise_for :students
then a link_to to the new_student_registration path in
application.html.erb and then a simple_form in that registration view
under devise, after a user signs up the user will get a confirmation email
sent by sendgrid.
My question is won't that particular student's record be exposed during
the sequence from above? and hence that is where the
<%= @email %> comes from?
why can't I pass in the student id to be emailed as well?

Simplest way to restrict access to Cloudfront(S3) files from some users but not others

Simplest way to restrict access to Cloudfront(S3) files from some users
but not others

I'm just getting started with permissions on AWS S3 and Cloudfront so
please take it easy on me.
Two main questions:
I'd like to allow access to some users (e.g., those that are logged in)
but not others. I assume I need to be using ACLs instead of a bucket
policy since the former is more customizable in that you can identify the
user in the URL with query parameters. First of all is this correct? Can
someone point me to the plainest english description of how to do this on
a file/user-by-file/user basis? The documentation on ACL confuses the heck
out of me.
I'd also like to restrict access such that people can only view content on
my-site.com and not your-site.com. Unfortunately the S3 documentation
example bucket policy for this has no effect on access for my demo bucket
(see code below, slightly adapted from AWS docs). Moreover, if I need to
foremost be focusing on allowing user-by-user access, do I even want to be
defining a bucket policy?
I realize i'm not even touching on how to make this work in the context of
Cloudfront (the ultimate goal) but any thoughts on questions 1 and 2 would
be greatly appreciated and mentioning Cloudfront would be a bonus at this
point.
`
{
"Version": "2008-10-17",
"Id":"http referer policy example",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*",
"Condition": {
"StringLike": {
"aws:Referer": [
"https://mysite.com/*",
"https://www.mysite.com/*"
]
}
}
}
]
}

Benefit of defining success/failure function instead of using success/!success

Benefit of defining success/failure function instead of using
success/!success

I was reading man page of gearman code
(http://manpages.ubuntu.com/manpages/precise/man3/gearman_success.3.html).
They are having two functions
bool gearman_success(gearman_return_t rc)
bool gearman_failed(gearman_return_t rc)
And code of those functions look like (libgearman-1.0/return.h):
static inline bool gearman_failed(enum gearman_return_t rc)
{
return rc != GEARMAN_SUCCESS;
}
static inline bool gearman_success(enum gearman_return_t rc)
{
return rc == GEARMAN_SUCCESS;
}
Both function does nearly same thing. One return true and another false.
What is the benefit of this code ?
Why not just have !gearman_success
Is there benefit of coding pattern or something , which I am missing here.

How to put data from various .cshtm files into of _Layout.cshtml?

How to put data from various .cshtm files into of _Layout.cshtml?

My _Layout.cshtml file has three "div" situated in one "div"(div
id="content"). The full code is:
<body id="bckgrimg">
<div id="content">
<div id="leftcolumn">
<ul >
<li><a href="home/contactus">Contact us</a></li>
<li><a href="home/aboutus">About us</a></li>
</ul>
</div>
<div id="centercolumn">
We'll put something useful here later
</div>
<div id="rightcolumn">
<div id="gallery">
<a href="../Slide1.JPG"><img src="..."/></a>
<a href="../horse_B.jpg"><img src="..."/></a>
<a href="../shore_B.jpg"><img src="..."/></a>
</div>
</div>
</div>
I have tried to put data by writing "some text" in xxx.cshtml but I just
add new element on a web page as I have yet created in _Layout.cshtml. I
just would like to put exactly data from various .cshtml files into of
_Layout.cshtml.
Is it possible to put data from xxx.cshtml file into (Where it is wtiiten
"We'll put something useful here later") of_Layout.cshtml?

Printed text in while loop doesn't act as expected

Printed text in while loop doesn't act as expected

This code:
while ($row = mysql_fetch_assoc($result)) {
$username=$row["username"];
$currentroles[$username]=$row["role"];
print "abc";
echo "<tr><td>$username</td>";
echo "def";
echo "<td><select name=\"role[$username]\">";
if($row["role"]=='admin')
{
echo "<option value=\"admin\">admin</option>";
echo "<option value=\"user\">user</option>";
}
else if($row["role"]=='user')
{
echo "<option value=\"user\">user</option>";
echo "<option value=\"admin\">admin</option>";
}
echo "</select></td></tr><br/>";
}
Produces this page:

(this is just a part of the page, there are as many users with a dropdown
list as "abcdef"s)
I have no idea why are the "abc", "def" strings at the top of the page. If
I take them out, there are empty lines in the page (instead of "abcdef)",
even though I never printed <br>. What's going on?

User defined Objects equality always returns false

User defined Objects equality always returns false

Class Product def initialize(name, qty) @name = name @qty = qty end def
to_s "#{@name}, #{@qty}" end end
irb> Product.new("Amazon", 3) == Product.new ("Amazon", 3) irb> false
Ruby always returns false for these type of user defined objects which is
wrong, how to make them true if they are equal and false if they are wrong

Tuesday, 17 September 2013

How do I initialize an instance variable?

How do I initialize an instance variable?

I have a class called Countdown with a constructor:
Countdown(int[][][] countdown): How do I initialize an instance variable
to reference the countdown thats passed into the constructor as a
parameter
Many thanks!