Hy,
I have a profile x, that has a born_date and then i want to get all the profiles that has more or less 5 years.
If profile x has 20 years, i want every profile that has between 15 and 25 years.
Here i need some date calculations and i dont really know how to do it. You have some ideas? ;)
I have this query and I have an error:
images = Image.find_by_sql('PREPARE stmt FROM \'
SELECT *
FROM images AS i
WHERE i.on_id = 1 AND i.on_type = "profile"
ORDER BY i.updated_at
LIMIT ?, 6\
'; SET @lower_limit := ((5 DIV 6) * 6); EXECUTE stmt USING @lower_limit;')
Mysql::Error: You have an error in
your SQL syntax; check the manual that
corresponds to your MySQL server
version for the right syntax to use
near 'SET @lower_limit := ((5 DIV 6) *
6); EXECUTE stmt USING @lower_limit'
at line 1: PREPARE stmt FROM ' SELECT
* FROM images AS i WHERE i.on_id = 1 AND i.on_type = "profile" ORDER BY
i.updated_at LIMIT ?, 6'; SET
@lower_limit := ((5 DIV 6) * 6);
EXECUTE stmt USING @lower_limit;
EDIT:
after finding the answer to: http://stackoverflow.com/questions/2566620/mysql-i-need-to-get-the-offset-of-a-item-in-a-query i need another help here to port it to rails.
Rails: url_for to be available in a isolated class that must be instanced:
class ProfilePresenter < ActionController::Base
attr_reader :profile
def initialize(profile)
super
@a = url_for(:controller => 'profiles', :action => 'view', :profile_url => 'dd')
@a
@profile = profile
end
end
How to make the url_for work?
i tried to extend the ActionController::Base and the ActionView::Base and i cant :s
Hy,
I was thinking that all my website will have use of cells, using the known plugin cell for rails, so this is my idea:
A table that contains 3 fields: id, view_name and layout. the layout will be a serialized hash.
When a request is made, the layout field is requested and then in the view, default layout, will be unserialized the layout var, that looks like this:
@layout[:sidecol][:gallery] = {... some params for it...};
@layout[:maincol][:comments] = {..params...};
In the <% #ruby code to render the cells in the @layout[:sidecol] % will be some ruby code that will loop over the @layout[:sidecol] and render all cells in it. the same occurs in the maincol div.
What do you think?
Positive in my opinion:
More modular
controller is used only for post
easy change of structure
easier to implement some kind of traking to see diferences on what layout is better or not.
Negative:
not found yet
Hy!
I have my project with pydev and looks like this:
ProjectName
-src
-gaesessions
-geo
-static_files
-app
is this ok?
I really don't like to have the gaesessions and geo in my root, but their namespace are by root. I would like to have a structure like this:
ProjectName
-src
-python
-thirdParty
-gaesessions
-geo
-app
-static_files
is this possible?
or even better would be to make them as a library. this would be the best thing, but how to do this in eclipse and then when deploy my app, to deploy with those files too? thanks
Code:
var connection = mongoose.createConnection('mongodb://localhost:9000/' + databaseName);
connection.db.dropDatabase(function(err){
// never reach this point!
debugger;
console.log(err);
console.log('-------------->Dropped database: ' + databaseName);
});
If I do connection.open it says that it's already opening and no multiple calls to "open" are supported for the same connection.
Even this doesn't work
var conn = mongoose.createConnection('mongodb://localhost',databaseName, 9000, {}, function(){
console.log('created'); // is reached
conn.db.dropDatabase(callback); // but the callback is not called anyway
});
What is the problem? ("mongoose": "3.1.0")
thanks
I have this:
app/modules/grid_module.rb
app/modules/grid.html.haml
then in my view:
app/views/layouts/default.html.haml
I want to make a new instance of the grid_module and render it content. Its content is into the grid.html.haml and this file can only use the instance vars set in the grid_module.rb
is this possible to do? (the grid name is just an example, it must be more flexible, to load the html.haml file based on the .rb class)
the grid_module must has access to models too*
like this: User.find_by_id(4)
thanks for help
class ProfilePresenter < ActionView::Base
def initialize
super
url_for # i got: You have a nil object when you didn't expect it!
# The error occurred while evaluating nil.url_for
end
end
url_for doesn't work. why?
i make a new instance like this
ProfilePresenter.new
I have in my model:
def presenter
@presenter ||= ProfilePresenter.new(self)
@presenter
end
The ProfilePresenter is a class that has methods like, get_link(), get_img_url(size), get_sex(), get_relationship_status() and other methods that have not to do with the model, not even with the controller but is used multiple times in the view.
So now i use them by doing this:
Profile.presenter.get_link
# or
Profile.presenter.get_img_url('thumb') # returns the path of the image. is not used to make a db query
Hy,
I was looking for a software to model an application, because is becoming too big.
Like this:
Class - A
Methods - a, b, c, d, e
Class - B
Methods - a, b, c, d, e
This should be in graphical mode, Classes are some boxes, and the methods are in the box.
Then I would like to be able to make a arrow from one method to another.
Do you know some good software?
thanks
I'm thinking of storing the view, what i mean by view is like this:
app/views/profiles/index.html.haml
into this i would do
$view = self
then in other parts of my app i would use and edit the $view var.
it might get troubles?
I have:
var f1 = function(a){
alert(a)
}
var f2 = function(data, method){
method(data) // the problem is here,
// the method f1 is not called. Is there a way to call that method f1?
// the method f1 might not be in this scope, the method f1 can
// be in a class or like this...
}
f2(a, f1)
The question is: Is there a way to call that f1 from f2, from the passed method?
thanks
In Profile model class
def add_friendship_request(friend_id)
Friendship.testing2 # doesnt work
Profile.testing2 # work
end
def self.testing2
'ss'
end
in my Friendship model class
def self.testing2
'ss'
end
I got this error:
undefined method `testing2' for #<Class:0x58eea7c>
I need to generate a string of 7 chars that is based on the id of the row. So knowing the id of the image and a secret key, i should get the generated string.
the string must contain chars from "a" to "z" and numbers from 0 to 9.
I have a dir that contains photos like this
dir/p3/i2/s21/thumb.jpg
the generated string is p3i2s21, then is used to calculate the path of the image.
Can you give examples of books that teach large web app development?
it must not be focused on a programming language, but to be generical with the concepts and structure.
thanks :)
Rails: i have a class method and i want to modify something of the instance
something like this:
class Test < Main
template :box
def test
# here I want to access the template name, that is box
end
end
class Main
def initialize
end
def self.template(name)
# here I have to save somehow the template name
# remember is not an instance.
end
end
that is similar to the model classes:
# in the model
has_many :projects
How do I do it?
EDIT: I need to generate a string of 7 chars that is based on the id of the row. So knowing the id of the image and a secret key, i should get the generated string.
the string must contain chars from "a" to "z" and numbers from 0 to 9.
I have a dir that contains photos like this
dir/p3/i2/s21/thumb.jpg
the generated string is p3i2s21, then is used to calculate the path of the image.
EDIT:
currently im using the id of the image:
id = 55
then i modify and i get
path = 000000055
then path = "000/000/055"
then path = "000/000/055/thumb.jpg"
ready to use!
now i want something more clever because is easy to track down all the images from a server, because ids are sequencial: 1, 2, 3, 4, 5, 6...
so i must think of creating from 55 a string that is 7 char length and will not overlap with other numbers. I can even transform the 55 to 0000055 and from this convert to a 7 char length string using a secret string. then when i got the secret string and the id i want to get back that 7 char length string.
Is this possible? i was thinking about hases but they only uses 0-9 and a-e and are more chars.. :s
Im thinking of storing the view, what i mean by view is like this:
app/views/profiles/index.html.haml
into this i would do
$view = self
then in other parts of my app i would use and edit the $view var.
it might get troubles?
Hy,
i have a div with relative position (CSS) and i want to make it to move on the screen, changing the left property.
This should be a smooth transition from (left: 0px;) to (left: 100px;).
Thanks