Ok, as I slowly start to put together my first rails app, I''m having some problems with table joins and doing it the "Rails" way. Traditionally when I want to join tables, I would either have foreign keys or manually set the ID of one table to another column in the joining table (for example Profile table has a column called user_id that corresponds to the Id column in the User table.) I know that Rails does auto joins and all that good stuff and all you gotta do is define <table_name>_id in the joining table and also specify it in the Models, but I am not entirely sure how this is done or if I am doing it right. Here is what I am trying to accomplish and maybe somebody could give me some hints on how to do it. I have a User table which holds basic user information, login information, etc. Then I also have a Profile table which will hold more information about the user. The reason for a seperate table to hold the profile is because in the future I plan to allow for multiple profiles per user. So in essense, User has_many :profiles and Profile belongs_to :User, which I have defined in my Models. Every time a new user is created (they successfully sign up), I would like a profile to be created as well. I would like this profile to be associated to this user, but all the fields could be empty (they all allow NULL values, except for the id and user_id fields.) Is this something I have to do manually after I do a @user.save or is there a way to have Rails automatically do this for me since I have defined the relationship between these two tables in my Models? The way I am doing it now is, when I call @user.save and it is successful, I then create a new @profile Profile.new(@params[''profile'']) and set the @profile.user_id @user.id and then calld @profile.save. This seems to be working fine, but it seems like I shouldn''t have to do all of this.. or maybe I do? Also, since I have created the relationship between these two tables, shouldn''t I be able to access the Profile information using my @user instance variable? or do I need to have a seperate @profile variable which is assigned by @profile = Profile.find_by_user_id(@user.id) ? I appreciate the feedback. -- - Ramin http://www.getintothis.com/blog
@user.profile.create(@params[:profile]) and @user.profile On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ok, as I slowly start to put together my first rails app, I''m having > some problems with table joins and doing it the "Rails" way. > Traditionally when I want to join tables, I would either have foreign > keys or manually set the ID of one table to another column in the > joining table (for example Profile table has a column called user_id > that corresponds to the Id column in the User table.) > > I know that Rails does auto joins and all that good stuff and all you > gotta do is define <table_name>_id in the joining table and also > specify it in the Models, but I am not entirely sure how this is done > or if I am doing it right. > > Here is what I am trying to accomplish and maybe somebody could give > me some hints on how to do it. > > I have a User table which holds basic user information, login > information, etc. Then I also have a Profile table which will hold > more information about the user. The reason for a seperate table to > hold the profile is because in the future I plan to allow for multiple > profiles per user. So in essense, User has_many :profiles and Profile > belongs_to :User, which I have defined in my Models. > > Every time a new user is created (they successfully sign up), I would > like a profile to be created as well. I would like this profile to be > associated to this user, but all the fields could be empty (they all > allow NULL values, except for the id and user_id fields.) Is this > something I have to do manually after I do a @user.save or is there a > way to have Rails automatically do this for me since I have defined > the relationship between these two tables in my Models? > > The way I am doing it now is, when I call @user.save and it is > successful, I then create a new @profile > Profile.new(@params[''profile'']) and set the @profile.user_id > @user.id <http://user.id> and then calld @profile.save. This seems to be > working fine, > but it seems like I shouldn''t have to do all of this.. or maybe I do? > > Also, since I have created the relationship between these two tables, > shouldn''t I be able to access the Profile information using my @user > instance variable? or do I need to have a seperate @profile variable > which is assigned by @profile = Profile.find_by_user_id(@user.id<http://user.id>) > ? > > I appreciate the feedback. > -- > - Ramin > http://www.getintothis.com/blog > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Great.. i will try that .. thanks! On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @user.profile.create(@params[:profile]) > > and > > @user.profile > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Ok, as I slowly start to put together my first rails app, I''m having > > some problems with table joins and doing it the "Rails" way. > > Traditionally when I want to join tables, I would either have foreign > > keys or manually set the ID of one table to another column in the > > joining table (for example Profile table has a column called user_id > > that corresponds to the Id column in the User table.) > > > > I know that Rails does auto joins and all that good stuff and all you > > gotta do is define <table_name>_id in the joining table and also > > specify it in the Models, but I am not entirely sure how this is done > > or if I am doing it right. > > > > Here is what I am trying to accomplish and maybe somebody could give > > me some hints on how to do it. > > > > I have a User table which holds basic user information, login > > information, etc. Then I also have a Profile table which will hold > > more information about the user. The reason for a seperate table to > > hold the profile is because in the future I plan to allow for multiple > > profiles per user. So in essense, User has_many :profiles and Profile > > belongs_to :User, which I have defined in my Models. > > > > Every time a new user is created (they successfully sign up), I would > > like a profile to be created as well. I would like this profile to be > > associated to this user, but all the fields could be empty (they all > > allow NULL values, except for the id and user_id fields.) Is this > > something I have to do manually after I do a @user.save or is there a > > way to have Rails automatically do this for me since I have defined > > the relationship between these two tables in my Models? > > > > The way I am doing it now is, when I call @user.save and it is > > successful, I then create a new @profile > > Profile.new(@params[''profile'']) and set the @ profile.user_id > > @user.id and then calld @profile.save. This seems to be working fine, > > but it seems like I shouldn''t have to do all of this.. or maybe I do? > > > > Also, since I have created the relationship between these two tables, > > shouldn''t I be able to access the Profile information using my @user > > instance variable? or do I need to have a seperate @profile variable > > which is assigned by @profile = Profile.find_by_user_id(@ user.id) ? > > > > I appreciate the feedback. > > -- > > - Ramin > > http://www.getintothis.com/blog > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > >-- - Ramin http://www.getintothis.com/blog
I am getting the following error:
undefined method `profile'' for #<User:0xb78e9884>
code snippet from my signup method:
def signup
case @request.method
when :post
@params[''user''].delete(''form'')
@user = User.new(@params[''user''])
@user.profile.create(@params[''profile'']) # <-- added
this
# do I need to put the above line somewhere else? like
# after the user.transaction or @user.save ?
begin
User.transaction(@user) do
if @user.save
... more code ...
end
end
end
end
end
On 9/15/05, Patrick McCafferty
<ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> @user.profile.create(@params[:profile])
>
> and
>
> @user.profile
>
>
> On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> >
> > Ok, as I slowly start to put together my first rails app, I''m
having
> > some problems with table joins and doing it the "Rails" way.
> > Traditionally when I want to join tables, I would either have foreign
> > keys or manually set the ID of one table to another column in the
> > joining table (for example Profile table has a column called user_id
> > that corresponds to the Id column in the User table.)
> >
> > I know that Rails does auto joins and all that good stuff and all you
> > gotta do is define <table_name>_id in the joining table and also
> > specify it in the Models, but I am not entirely sure how this is done
> > or if I am doing it right.
> >
> > Here is what I am trying to accomplish and maybe somebody could give
> > me some hints on how to do it.
> >
> > I have a User table which holds basic user information, login
> > information, etc. Then I also have a Profile table which will hold
> > more information about the user. The reason for a seperate table to
> > hold the profile is because in the future I plan to allow for multiple
> > profiles per user. So in essense, User has_many :profiles and Profile
> > belongs_to :User, which I have defined in my Models.
> >
> > Every time a new user is created (they successfully sign up), I would
> > like a profile to be created as well. I would like this profile to be
> > associated to this user, but all the fields could be empty (they all
> > allow NULL values, except for the id and user_id fields.) Is this
> > something I have to do manually after I do a @user.save or is there a
> > way to have Rails automatically do this for me since I have defined
> > the relationship between these two tables in my Models?
> >
> > The way I am doing it now is, when I call @user.save and it is
> > successful, I then create a new @profile > >
Profile.new(@params[''profile'']) and set the @ profile.user_id
> > @user.id and then calld @profile.save. This seems to be working fine,
> > but it seems like I shouldn''t have to do all of this.. or
maybe I do?
> >
> > Also, since I have created the relationship between these two tables,
> > shouldn''t I be able to access the Profile information using
my @user
> > instance variable? or do I need to have a seperate @profile variable
> > which is assigned by @profile = Profile.find_by_user_id(@ user.id) ?
> >
> > I appreciate the feedback.
> > --
> > - Ramin
> > http://www.getintothis.com/blog
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
>
--
- Ramin
http://www.getintothis.com/blog
Nevermind... I was specifying @user.profile.create ... when I should''ve been specifying @user.profiles.create (plural form!) ... I get confused with all the singular/plural naming conventions... =P @user.profiles.create(@params[''profile'']) worked just fine! thanks again! On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am getting the following error: > undefined method `profile'' for #<User:0xb78e9884> > > code snippet from my signup method: > > def signup > case @request.method > when :post > @params[''user''].delete(''form'') > @user = User.new(@params[''user'']) > @user.profile.create(@params[''profile'']) # <-- added this > > # do I need to put the above line somewhere else? like > # after the user.transaction or @user.save ? > > begin > User.transaction(@user) do > if @user.save > ... more code ... > end > end > end > end > end > > > On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > @user.profile.create(@params[:profile]) > > > > and > > > > @user.profile > > > > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Ok, as I slowly start to put together my first rails app, I''m having > > > some problems with table joins and doing it the "Rails" way. > > > Traditionally when I want to join tables, I would either have foreign > > > keys or manually set the ID of one table to another column in the > > > joining table (for example Profile table has a column called user_id > > > that corresponds to the Id column in the User table.) > > > > > > I know that Rails does auto joins and all that good stuff and all you > > > gotta do is define <table_name>_id in the joining table and also > > > specify it in the Models, but I am not entirely sure how this is done > > > or if I am doing it right. > > > > > > Here is what I am trying to accomplish and maybe somebody could give > > > me some hints on how to do it. > > > > > > I have a User table which holds basic user information, login > > > information, etc. Then I also have a Profile table which will hold > > > more information about the user. The reason for a seperate table to > > > hold the profile is because in the future I plan to allow for multiple > > > profiles per user. So in essense, User has_many :profiles and Profile > > > belongs_to :User, which I have defined in my Models. > > > > > > Every time a new user is created (they successfully sign up), I would > > > like a profile to be created as well. I would like this profile to be > > > associated to this user, but all the fields could be empty (they all > > > allow NULL values, except for the id and user_id fields.) Is this > > > something I have to do manually after I do a @user.save or is there a > > > way to have Rails automatically do this for me since I have defined > > > the relationship between these two tables in my Models? > > > > > > The way I am doing it now is, when I call @user.save and it is > > > successful, I then create a new @profile > > > Profile.new(@params[''profile'']) and set the @ profile.user_id > > > @user.id and then calld @profile.save. This seems to be working fine, > > > but it seems like I shouldn''t have to do all of this.. or maybe I do? > > > > > > Also, since I have created the relationship between these two tables, > > > shouldn''t I be able to access the Profile information using my @user > > > instance variable? or do I need to have a seperate @profile variable > > > which is assigned by @profile = Profile.find_by_user_id(@ user.id) ? > > > > > > I appreciate the feedback. > > > -- > > > - Ramin > > > http://www.getintothis.com/blog > > > _______________________________________________ > > > Rails mailing list > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > -- > - Ramin > http://www.getintothis.com/blog >-- - Ramin http://www.getintothis.com/blog
speechexpert
2005-Sep-15 15:58 UTC
How to make your Rails into an exe for windows, linux, mac
Please excuse any typos, i''m doing this from memory: following assumes your application is at D:\application 1. create a file in application called init.rb containing line system ''ruby script/server'' 2. Go to D:\ 3. Run ruby tar2rubyscript.rb application/ 4 Run Rubyscript2exe application.rb 5. Test the runnung server, then hit ctrl-C 6. application.exe is created in D:\ Any errors in above please report to this mail list. Thanks to Erik Veenstra for this magic - the programs are freeware on the net...
That''s weird, too, because user doesn''t :have_many profiles, does it? If it does then @user.profiles.create makes sense. Otherwise, for better looking code you should use @user.profile = Profile.new/create(@params[:profile]) . (The difference between .new and .create is that .create saves the record, whereas .new requires you to save it yourself (or save the associated user)) On 9/16/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Nevermind... I was specifying @user.profile.create ... when I > should''ve been specifying @user.profiles.create (plural form!) ... I > get confused with all the singular/plural naming conventions... =P > > @user.profiles.create(@params[''profile'']) worked just fine! thanks again! > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I am getting the following error: > > undefined method `profile'' for #<User:0xb78e9884> > > > > code snippet from my signup method: > > > > def signup > > case @request.method > > when :post > > @params[''user''].delete(''form'') > > @user = User.new(@params[''user'']) > > @user.profile.create(@params[''profile'']) # <-- added this > > > > # do I need to put the above line somewhere else? like > > # after the user.transaction or @user.save ? > > > > begin > > User.transaction(@user) do > > if @user.save > > ... more code ... > > end > > end > > end > > end > > end > > > > > > On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > @user.profile.create(@params[:profile]) > > > > > > and > > > > > > @user.profile > > > > > > > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > Ok, as I slowly start to put together my first rails app, I''m having > > > > some problems with table joins and doing it the "Rails" way. > > > > Traditionally when I want to join tables, I would either have > foreign > > > > keys or manually set the ID of one table to another column in the > > > > joining table (for example Profile table has a column called user_id > > > > that corresponds to the Id column in the User table.) > > > > > > > > I know that Rails does auto joins and all that good stuff and all > you > > > > gotta do is define <table_name>_id in the joining table and also > > > > specify it in the Models, but I am not entirely sure how this is > done > > > > or if I am doing it right. > > > > > > > > Here is what I am trying to accomplish and maybe somebody could give > > > > me some hints on how to do it. > > > > > > > > I have a User table which holds basic user information, login > > > > information, etc. Then I also have a Profile table which will hold > > > > more information about the user. The reason for a seperate table to > > > > hold the profile is because in the future I plan to allow for > multiple > > > > profiles per user. So in essense, User has_many :profiles and > Profile > > > > belongs_to :User, which I have defined in my Models. > > > > > > > > Every time a new user is created (they successfully sign up), I > would > > > > like a profile to be created as well. I would like this profile to > be > > > > associated to this user, but all the fields could be empty (they all > > > > allow NULL values, except for the id and user_id fields.) Is this > > > > something I have to do manually after I do a @user.save or is there > a > > > > way to have Rails automatically do this for me since I have defined > > > > the relationship between these two tables in my Models? > > > > > > > > The way I am doing it now is, when I call @user.save and it is > > > > successful, I then create a new @profile > > > > Profile.new(@params[''profile'']) and set the @ profile.user_id > > > > @user.id <http://user.id> and then calld @profile.save. This seems > to be working fine, > > > > but it seems like I shouldn''t have to do all of this.. or maybe I > do? > > > > > > > > Also, since I have created the relationship between these two > tables, > > > > shouldn''t I be able to access the Profile information using my @user > > > > instance variable? or do I need to have a seperate @profile variable > > > > which is assigned by @profile = Profile.find_by_user_id(@ user.id<http://user.id>) > ? > > > > > > > > I appreciate the feedback. > > > > -- > > > > - Ramin > > > > http://www.getintothis.com/blog > > > > _______________________________________________ > > > > Rails mailing list > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > -- > > - Ramin > > http://www.getintothis.com/blog > > > > > -- > - Ramin > http://www.getintothis.com/blog >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
choonkeat
2005-Sep-15 16:53 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Hmm. doesn''t "system ''ruby script/server''" mean the target machine running the EXE will now require ruby installed?... and thus defeating the purpose of making it a standalone executable in the first place? correct me if i''m wrong there. For me.. I merely copied the script/server as init.rb, and removed the hence unnecessary ''/..'' inside the script. On 9/15/05, speechexpert <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> > Please excuse any typos, i''m doing this from memory: > > following assumes your application is at D:\application > > > 1. create a file in application called init.rb containing line system > ''ruby > script/server'' > 2. Go to D:\ > 3. Run ruby tar2rubyscript.rb application/ > 4 Run Rubyscript2exe application.rb > 5. Test the runnung server, then hit ctrl-C > 6. application.exe is created in D:\ > > Any errors in above please report to this mail list. > > Thanks to Erik Veenstra for this magic - the programs are freeware on the > net... > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
My User model does have has_many :profiles ... so now I am doing: @profile = @user.profiles.create(@params[''profile'']) but you''re suggesting that I do: @user.profile = Profile.create(@params[''profile'']) ? or maybe even, @user.profiles = Profile.create(@params[''profile'']) since I have the has_many defined. Do I even need the has_many defined in my User model? My users could have 1 or more profiles.. A question about destroying a user... if I destroy a user with 1 or more profile entries, will those entries also get deleted from the database? I want them to get deleted. I have added this to my Profile model: belongs_to :user, :dependent => true However it seems like the profiles aren''t getting deleted when I delete the user. Do I need to manually delete the profiles myself by calling something like user.profiles.destroy() and then user.destroy() ? Or will user.destroy() also destroy the profiles associated with it because of the dependent => true thing? Thanks On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That''s weird, too, because user doesn''t :have_many profiles, does it? If it > does then @user.profiles.create makes sense. Otherwise, for better looking > code you should use @user.profile = Profile.new/create(@params[:profile]) . > > (The difference between .new and .create is that .create saves the record, > whereas .new requires you to save it yourself (or save the associated user)) > > > On 9/16/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Nevermind... I was specifying @user.profile.create ... when I > > should''ve been specifying @user.profiles.create (plural form!) ... I > > get confused with all the singular/plural naming conventions... =P > > > > @user.profiles.create (@params[''profile'']) worked just fine! thanks again! > > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I am getting the following error: > > > undefined method `profile'' for #<User:0xb78e9884> > > > > > > code snippet from my signup method: > > > > > > def signup > > > case @request.method > > > when :post > > > @params[''user''].delete(''form'') > > > @user = User.new(@params[''user'']) > > > @user.profile.create(@params[''profile'']) # <-- added this > > > > > > # do I need to put the above line somewhere else? like > > > # after the user.transaction or @user.save ? > > > > > > begin > > > User.transaction(@user) do > > > if @user.save > > > ... more code ... > > > end > > > end > > > end > > > end > > > end > > > > > > > > > On 9/15/05, Patrick McCafferty < ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > @user.profile.create(@params[:profile]) > > > > > > > > and > > > > > > > > @user.profile > > > > > > > > > > > > On 9/15/05, Ramin < i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > Ok, as I slowly start to put together my first rails app, I''m having > > > > > some problems with table joins and doing it the "Rails" way. > > > > > Traditionally when I want to join tables, I would either have > foreign > > > > > keys or manually set the ID of one table to another column in the > > > > > joining table (for example Profile table has a column called user_id > > > > > that corresponds to the Id column in the User table.) > > > > > > > > > > I know that Rails does auto joins and all that good stuff and all > you > > > > > gotta do is define <table_name>_id in the joining table and also > > > > > specify it in the Models, but I am not entirely sure how this is > done > > > > > or if I am doing it right. > > > > > > > > > > Here is what I am trying to accomplish and maybe somebody could give > > > > > me some hints on how to do it. > > > > > > > > > > I have a User table which holds basic user information, login > > > > > information, etc. Then I also have a Profile table which will hold > > > > > more information about the user. The reason for a seperate table to > > > > > hold the profile is because in the future I plan to allow for > multiple > > > > > profiles per user. So in essense, User has_many :profiles and > Profile > > > > > belongs_to :User, which I have defined in my Models. > > > > > > > > > > Every time a new user is created (they successfully sign up), I > would > > > > > like a profile to be created as well. I would like this profile to > be > > > > > associated to this user, but all the fields could be empty (they all > > > > > allow NULL values, except for the id and user_id fields.) Is this > > > > > something I have to do manually after I do a @ user.save or is there > a > > > > > way to have Rails automatically do this for me since I have defined > > > > > the relationship between these two tables in my Models? > > > > > > > > > > The way I am doing it now is, when I call @ user.save and it is > > > > > successful, I then create a new @profile > > > > > Profile.new(@params[''profile'']) and set the @ profile.user_id > > > > > @user.id and then calld @ profile.save. This seems to be working > fine, > > > > > but it seems like I shouldn''t have to do all of this.. or maybe I > do? > > > > > > > > > > Also, since I have created the relationship between these two > tables, > > > > > shouldn''t I be able to access the Profile information using my @user > > > > > instance variable? or do I need to have a seperate @profile variable > > > > > which is assigned by @profile = Profile.find_by_user_id(@ user.id) ? > > > > > > > > > > I appreciate the feedback. > > > > > -- > > > > > - Ramin > > > > > http://www.getintothis.com/blog > > > > > _______________________________________________ > > > > > Rails mailing list > > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > > > > > -- > > > - Ramin > > > http://www.getintothis.com/blog > > > > > > > > > -- > > - Ramin > > http://www.getintothis.com/blog > > > >-- - Ramin http://www.getintothis.com/blog
choonkeat
2005-Sep-15 17:12 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Just to add, for it to be really standalone.. I used sqlite for the
database:
1. copied sqlite libs into the ${RAILS_ROOT}/vendor/ folder,
2. configured ${RAILS_ROOT}/config/database.yml to use dbfile:
/sqlite_db (so that db sits at root folder, not inside the temp dir)
3. inside ${RAILS_ROOT}/init.rb, copy a blank
${RAILS_ROOT}/db/sqlite_db into /sqlite_db if it doesn''t already
exist
4. added sqlite.dll to the ${RAILS_ROOT}
Works very well.. except when app terminates, the temp folder can''t be
removed properly:
Permission denied - sqlite.dll
Permission denied - sqlite_api.so
If anyone can solve that, it''ll be kewl (Otherwise, I''ll
fallback on "on
next startup, look for old folder and remove.. ")
License wise.. I''m not too sure on implications of distributing EXE
with
embedded sqlite... anyone?
On 9/16/05, choonkeat <choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hmm. doesn''t "system ''ruby
script/server''" mean the target machine running
> the EXE will now require ruby installed?... and thus defeating the purpose
> of making it a standalone executable in the first place? correct me if
i''m
> wrong there.
>
> For me.. I merely copied the script/server as init.rb, and removed the
> hence unnecessary '' /..'' inside the script.
>
>
>
>
> On 9/15/05, speechexpert
<speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:
> >
> > Please excuse any typos, i''m doing this from memory:
> >
> > following assumes your application is at D:\application
> >
> >
> > 1. create a file in application called init.rb containing line system
> > ''ruby
> > script/server''
> > 2. Go to D:\
> > 3. Run ruby tar2rubyscript.rb application/
> > 4 Run Rubyscript2exe application.rb
> > 5. Test the runnung server, then hit ctrl-C
> > 6. application.exe is created in D:\
> >
> > Any errors in above please report to this mail list.
> >
> > Thanks to Erik Veenstra for this magic - the programs are freeware on
> > the
> > net...
> >
> >
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
Alex Young
2005-Sep-15 17:15 UTC
Re: How to make your Rails into an exe for windows, linux, mac
choonkeat wrote:> License wise.. I''m not too sure on implications of distributing EXE with > embedded sqlite... anyone?SQLite is public domain code. As in, you can do whatever you want with it - including charge for it. Check http://www.sqlite.org/copyright.html. Specific wrappers might not be, though... -- Alex
I found out that I had the :dependent => true on the wrong Model... I had to define it on my User model after has_many,so has_many => :profiles, :dependent => true works just fine and the profiles are deleted when I delete the user. Thanks again for the help! Rails rocks my world! =] On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> My User model does have has_many :profiles ... so now I am doing: > > @profile = @user.profiles.create(@params[''profile'']) > > but you''re suggesting that I do: > > @user.profile = Profile.create(@params[''profile'']) ? or maybe even, > @user.profiles = Profile.create(@params[''profile'']) since I have the > has_many defined. > > Do I even need the has_many defined in my User model? My users could > have 1 or more profiles.. > > A question about destroying a user... if I destroy a user with 1 or > more profile entries, will those entries also get deleted from the > database? I want them to get deleted. I have added this to my Profile > model: > > belongs_to :user, :dependent => true > > However it seems like the profiles aren''t getting deleted when I > delete the user. Do I need to manually delete the profiles myself by > calling something like user.profiles.destroy() and then user.destroy() > ? Or will user.destroy() also destroy the profiles associated with it > because of the dependent => true thing? > > Thanks > > > On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > That''s weird, too, because user doesn''t :have_many profiles, does it? If it > > does then @user.profiles.create makes sense. Otherwise, for better looking > > code you should use @user.profile = Profile.new/create(@params[:profile]) . > > > > (The difference between .new and .create is that .create saves the record, > > whereas .new requires you to save it yourself (or save the associated user)) > > > > > > On 9/16/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Nevermind... I was specifying @user.profile.create ... when I > > > should''ve been specifying @user.profiles.create (plural form!) ... I > > > get confused with all the singular/plural naming conventions... =P > > > > > > @user.profiles.create (@params[''profile'']) worked just fine! thanks again! > > > > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I am getting the following error: > > > > undefined method `profile'' for #<User:0xb78e9884> > > > > > > > > code snippet from my signup method: > > > > > > > > def signup > > > > case @request.method > > > > when :post > > > > @params[''user''].delete(''form'') > > > > @user = User.new(@params[''user'']) > > > > @user.profile.create(@params[''profile'']) # <-- added this > > > > > > > > # do I need to put the above line somewhere else? like > > > > # after the user.transaction or @user.save ? > > > > > > > > begin > > > > User.transaction(@user) do > > > > if @user.save > > > > ... more code ... > > > > end > > > > end > > > > end > > > > end > > > > end > > > > > > > > > > > > On 9/15/05, Patrick McCafferty < ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > @user.profile.create(@params[:profile]) > > > > > > > > > > and > > > > > > > > > > @user.profile > > > > > > > > > > > > > > > On 9/15/05, Ramin < i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > Ok, as I slowly start to put together my first rails app, I''m having > > > > > > some problems with table joins and doing it the "Rails" way. > > > > > > Traditionally when I want to join tables, I would either have > > foreign > > > > > > keys or manually set the ID of one table to another column in the > > > > > > joining table (for example Profile table has a column called user_id > > > > > > that corresponds to the Id column in the User table.) > > > > > > > > > > > > I know that Rails does auto joins and all that good stuff and all > > you > > > > > > gotta do is define <table_name>_id in the joining table and also > > > > > > specify it in the Models, but I am not entirely sure how this is > > done > > > > > > or if I am doing it right. > > > > > > > > > > > > Here is what I am trying to accomplish and maybe somebody could give > > > > > > me some hints on how to do it. > > > > > > > > > > > > I have a User table which holds basic user information, login > > > > > > information, etc. Then I also have a Profile table which will hold > > > > > > more information about the user. The reason for a seperate table to > > > > > > hold the profile is because in the future I plan to allow for > > multiple > > > > > > profiles per user. So in essense, User has_many :profiles and > > Profile > > > > > > belongs_to :User, which I have defined in my Models. > > > > > > > > > > > > Every time a new user is created (they successfully sign up), I > > would > > > > > > like a profile to be created as well. I would like this profile to > > be > > > > > > associated to this user, but all the fields could be empty (they all > > > > > > allow NULL values, except for the id and user_id fields.) Is this > > > > > > something I have to do manually after I do a @ user.save or is there > > a > > > > > > way to have Rails automatically do this for me since I have defined > > > > > > the relationship between these two tables in my Models? > > > > > > > > > > > > The way I am doing it now is, when I call @ user.save and it is > > > > > > successful, I then create a new @profile > > > > > > Profile.new(@params[''profile'']) and set the @ profile.user_id > > > > > > @user.id and then calld @ profile.save. This seems to be working > > fine, > > > > > > but it seems like I shouldn''t have to do all of this.. or maybe I > > do? > > > > > > > > > > > > Also, since I have created the relationship between these two > > tables, > > > > > > shouldn''t I be able to access the Profile information using my @user > > > > > > instance variable? or do I need to have a seperate @profile variable > > > > > > which is assigned by @profile = Profile.find_by_user_id(@ user.id) ? > > > > > > > > > > > > I appreciate the feedback. > > > > > > -- > > > > > > - Ramin > > > > > > http://www.getintothis.com/blog > > > > > > _______________________________________________ > > > > > > Rails mailing list > > > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > - Ramin > > > > http://www.getintothis.com/blog > > > > > > > > > > > > > -- > > > - Ramin > > > http://www.getintothis.com/blog > > > > > > > > > > -- > - Ramin > http://www.getintothis.com/blog >-- - Ramin http://www.getintothis.com/blog
Justin Forder
2005-Sep-15 17:22 UTC
Re: How to make your Rails into an exe for windows, linux, mac
choonkeat wrote:> Hmm. doesn''t "system ''ruby script/server''" mean the target machine > running the EXE will now require ruby installed?... and thus defeating > the purpose of making it a standalone executable in the first place? > correct me if i''m wrong there.No, because RubyScript2Exe wraps up the application, Ruby, and the standard libraries... but what about the Rails gems? http://www.erikveen.dds.nl/tar2rubyscript/index.html http://www.erikveen.dds.nl/rubyscript2exe/index.html Ah.. the second of those says that the application''s dependencies are included. With respect to RubyGems, Erik writes: "I''m working on full support of RubyGems. The handling of require_gem and the mangling of $: are implemented and all files of a gem are embedded. I''ve tested just a couple of gems, not all of them. If you''ve troubles with a specific gem, please let me know" Justin> > For me.. I merely copied the script/server as init.rb, and removed the > hence unnecessary '' /..'' inside the script. > > > > > On 9/15/05, *speechexpert* <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org > <mailto:speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org>> wrote: > > Please excuse any typos, i''m doing this from memory: > > following assumes your application is at D:\application > > > 1. create a file in application called init.rb containing > line system ''ruby > script/server'' > 2. Go to D:\ > 3. Run ruby tar2rubyscript.rb application/ > 4 Run Rubyscript2exe application.rb > 5. Test the runnung server, then hit ctrl-C > 6. application.exe is created in D:\ > > Any errors in above please report to this mail list. > > Thanks to Erik Veenstra for this magic - the programs are freeware > on the > net... > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org <mailto:Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org> > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Anti-Virus. > Version: 7.0.344 / Virus Database: 267.10.25/102 - Release Date: 14/09/2005 >
No, if your User has_many :profiles then the correct syntax is, in fact, user.profiles.create(). The reason that this is the "right" way is that if you have counter caching enabled on your user model, that method will update the cache in memory, whereas profile.user_id = user_id would not. On 9/16/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I found out that I had the :dependent => true on the wrong Model... I > had to define it on my User model after has_many,so > > has_many => :profiles, :dependent => true > > works just fine and the profiles are deleted when I delete the user. > > Thanks again for the help! Rails rocks my world! =] > > > > On 9/15/05, Ramin < i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > My User model does have has_many :profiles ... so now I am doing: > > > > @profile = @user.profiles.create(@params[''profile'']) > > > > but you''re suggesting that I do: > > > > @user.profile = Profile.create(@params[''profile'']) ? or maybe even, > > @user.profiles = Profile.create(@params[''profile'']) since I have the > > has_many defined. > > > > Do I even need the has_many defined in my User model? My users could > > have 1 or more profiles.. > > > > A question about destroying a user... if I destroy a user with 1 or > > more profile entries, will those entries also get deleted from the > > database? I want them to get deleted. I have added this to my Profile > > model: > > > > belongs_to :user, :dependent => true > > > > However it seems like the profiles aren''t getting deleted when I > > delete the user. Do I need to manually delete the profiles myself by > > calling something like user.profiles.destroy() and then user.destroy() > > ? Or will user.destroy() also destroy the profiles associated with it > > because of the dependent => true thing? > > > > Thanks > > > > > > On 9/15/05, Patrick McCafferty <ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > That''s weird, too, because user doesn''t :have_many profiles, does it? > If it > > > does then @user.profiles.create makes sense. Otherwise, for better > looking > > > code you should use @user.profile = Profile.new/create(@params[:profile]) > . > > > > > > (The difference between .new and .create is that .create saves the > record, > > > whereas .new requires you to save it yourself (or save the associated > user)) > > > > > > > > > On 9/16/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Nevermind... I was specifying @user.profile.create ... when I > > > > should''ve been specifying @user.profiles.create (plural form!) ... I > > > > get confused with all the singular/plural naming conventions... =P > > > > > > > > @user.profiles.create (@params[''profile'']) worked just fine! thanks > again! > > > > > > > > On 9/15/05, Ramin <i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > wrote: > > > > > I am getting the following error: > > > > > undefined method `profile'' for #<User:0xb78e9884> > > > > > > > > > > code snippet from my signup method: > > > > > > > > > > def signup > > > > > case @request.method > > > > > when :post > > > > > @params[''user''].delete(''form'') > > > > > @user = User.new(@params[''user'']) > > > > > @user.profile.create(@params[''profile'']) # <-- added this > > > > > > > > > > # do I need to put the above line somewhere else? like > > > > > # after the user.transaction or @user.save ? > > > > > > > > > > begin > > > > > User.transaction(@user) do > > > > > if @user.save > > > > > ... more code ... > > > > > end > > > > > end > > > > > end > > > > > end > > > > > end > > > > > > > > > > > > > > > On 9/15/05, Patrick McCafferty < ryouga-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > @user.profile.create(@params[:profile]) > > > > > > > > > > > > and > > > > > > > > > > > > @user.profile > > > > > > > > > > > > > > > > > > On 9/15/05, Ramin < i8ramin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > > Ok, as I slowly start to put together my first rails app, I''m > having > > > > > > > some problems with table joins and doing it the "Rails" way. > > > > > > > Traditionally when I want to join tables, I would either have > > > foreign > > > > > > > keys or manually set the ID of one table to another column in > the > > > > > > > joining table (for example Profile table has a column called > user_id > > > > > > > that corresponds to the Id column in the User table.) > > > > > > > > > > > > > > I know that Rails does auto joins and all that good stuff and > all > > > you > > > > > > > gotta do is define <table_name>_id in the joining table and > also > > > > > > > specify it in the Models, but I am not entirely sure how this > is > > > done > > > > > > > or if I am doing it right. > > > > > > > > > > > > > > Here is what I am trying to accomplish and maybe somebody > could give > > > > > > > me some hints on how to do it. > > > > > > > > > > > > > > I have a User table which holds basic user information, login > > > > > > > information, etc. Then I also have a Profile table which will > hold > > > > > > > more information about the user. The reason for a seperate > table to > > > > > > > hold the profile is because in the future I plan to allow for > > > multiple > > > > > > > profiles per user. So in essense, User has_many :profiles and > > > Profile > > > > > > > belongs_to :User, which I have defined in my Models. > > > > > > > > > > > > > > Every time a new user is created (they successfully sign up), > I > > > would > > > > > > > like a profile to be created as well. I would like this > profile to > > > be > > > > > > > associated to this user, but all the fields could be empty > (they all > > > > > > > allow NULL values, except for the id and user_id fields.) Is > this > > > > > > > something I have to do manually after I do a @ user.save or is > there > > > a > > > > > > > way to have Rails automatically do this for me since I have > defined > > > > > > > the relationship between these two tables in my Models? > > > > > > > > > > > > > > The way I am doing it now is, when I call @ user.save and it > is > > > > > > > successful, I then create a new @profile > > > > > > > Profile.new(@params[''profile'']) and set the @ profile.user_id> > > > > > > @user.id <http://user.id> and then calld @ profile.save. This > seems to be working > > > fine, > > > > > > > but it seems like I shouldn''t have to do all of this.. or > maybe I > > > do? > > > > > > > > > > > > > > Also, since I have created the relationship between these two > > > tables, > > > > > > > shouldn''t I be able to access the Profile information using my > @user > > > > > > > instance variable? or do I need to have a seperate @profile > variable > > > > > > > which is assigned by @profile = Profile.find_by_user_id(@ user.id > <http://user.id>) ? > > > > > > > > > > > > > > I appreciate the feedback. > > > > > > > -- > > > > > > > - Ramin > > > > > > > http://www.getintothis.com/blog > > > > > > > _______________________________________________ > > > > > > > Rails mailing list > > > > > > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > > > > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > - Ramin > > > > > http://www.getintothis.com/blog > > > > > > > > > > > > > > > > > -- > > > > - Ramin > > > > http://www.getintothis.com/blog > > > > > > > > > > > > > > > > -- > > - Ramin > > http://www.getintothis.com/blog > > > > > -- > - Ramin > http://www.getintothis.com/blog >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Tom Jordan
2005-Sep-15 17:33 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Hi Choonkeat On 9/15/05, choonkeat <choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hmm. doesn''t "system ''ruby script/server''" mean the target machine running > the EXE will now require ruby installed?... and thus defeating the purpose > of making it a standalone executable in the first place? correct me if i''m > wrong there.No ruby does not need to be installed. It''s packaged up inside the .exe When the .exe is executed, everything is extracted and the embedded eee.exe puts the relative path bin/ into the path. see: http://www.erikveen.dds.nl/rubyscript2exe/index.html#3.4.0 for a way to see how everything is packaged. eg: myrails.exe --eee-justextract -- Tom Jordan -- "Nothing will ever be attempted, if all possible objections must first be overcome." - Samuel Johnson
Jarkko Laine
2005-Sep-15 18:45 UTC
Mailing list etiquette rant (Re: How to make your Rails into an exe for windows, linux, mac)
OK, this is an old rant, but as the list population has grown tremendously over the past months, I''ll restate it here: *DO NOT* reply to an old message when you are starting a new thread. It will make following the list with a thread-aware client (Mail.app, gmail to name a few) a pain because multiple threads get mixed up. This is nothing personal. But please, pretty please, when you have a new topic, send a new message to rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org, don''t reply to an existing message. //jarkko _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
speechexpert
2005-Sep-15 23:26 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Choonkeat,
Could you summarize? Exactly what are you using for your init.rb? Is it the
server file in script/ that is just re-named to init.rb?
(I seem to remember trying that, and it didn''t work. But memory could
be faulty. :)
Great SQLite comments.
Nice to have a concensus summary so a cookbook approach can be gotten...
Thanks
John B
----- Original Message -----
From: choonkeat
To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Sent: Thursday, September 15, 2005 9:53 AM
Subject: Re: [Rails] How to make your Rails into an exe for windows, linux,
mac
Hmm. doesn''t "system ''ruby
script/server''" mean the target machine running the EXE will now
require ruby installed?... and thus defeating the purpose of making it a
standalone executable in the first place? correct me if i''m wrong
there.
For me.. I merely copied the script/server as init.rb, and removed the hence
unnecessary '' /..'' inside the script.
On 9/15/05, speechexpert
<speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:
Please excuse any typos, i''m doing this from memory:
following assumes your application is at D:\application
1. create a file in application called init.rb containing line system
''ruby
script/server''
2. Go to D:\
3. Run ruby tar2rubyscript.rb application/
4 Run Rubyscript2exe application.rb
5. Test the runnung server, then hit ctrl-C
6. application.exe is created in D:\
Any errors in above please report to this mail list.
Thanks to Erik Veenstra for this magic - the programs are freeware on the
net...
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
------------------------------------------------------------------------------
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
choonkeat
2005-Sep-19 08:04 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Thanks for the great tip on --eee-justextract. missed that important option.
:-D
I''d met a very inconvenient warning trying to run Rails as a (windows)
desktop app since the produced exe runs off a temp dir.. Most
personal/desktop firewall (including microsoft''s) will prompt a
"block /
allow ruby.exe" everytime I run my EXE. This is un-desirable. At most, the
warning should only come up once.
What I did,
1. Create ${RAILS_ROOT}/init.rb
- I copied and modified the ${RAILS_ROOT}/scripts/server into
${RAILS_ROOT}/init.rb
- optionally, ${RAILS_ROOT}/init.rb can simply contain only
"system ''ruby scripts/server''"
2. tar2rubyscript ${RAILS_ROOT}
3. rubyscript2exe ${RAILS_ROOT}.rb
4. ${RAILS_ROOT}.exe --eee-justextract
5. Copy the new 4 files + 3 folders somewhere, this will be my
${BUNDLE_DIR}
- empty.rb
- bootstrap.rb
- app.eee
- eee.exe
- app/
- lib/
- bin/
6. Copy everything in ${RAILS_ROOT} into ${BUNDLE_DIR}/app
7. Create ${BUNDLE_DIR}/run.bat
cd app> ..\bin\ruby.exe -I ..\lib init.rb
>
Also, without the temp folder constraint and my files won''t be deleted
after
every run:
1. my sqlite db can be located safely within the ${BUNDLE_DIR}/app/db
folder, instead of / root folder
2. there''s no more Permission denied - sqlite.dll errors on closing
the app
So, my distribution will be a .zip file of ${BUNDLE_DIR}. Simply unzip and
execute "run.bat". At last, I''ve reached the Instiki-ish
no-step-3 goal :-D
Sweet!
PS: Bonus points, I can continue to tweak everything inside
${BUNDLE_DIR}/app, maintain them via CVS, and execute "run.bat" to
immediately test them. Zip up ${BUNDLE_DIR} and its ready to be distributed.
On 9/16/05, Tom Jordan <tdjordan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> Hi Choonkeat
>
> On 9/15/05, choonkeat
<choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > Hmm. doesn''t "system ''ruby
script/server''" mean the target machine
> running
> > the EXE will now require ruby installed?... and thus defeating the
> purpose
> > of making it a standalone executable in the first place? correct me if
> i''m
> > wrong there.
>
> No ruby does not need to be installed.
> It''s packaged up inside the .exe
> When the .exe is executed, everything is extracted and
> the embedded eee.exe puts the relative path bin/ into the path.
>
> see: http://www.erikveen.dds.nl/rubyscript2exe/index.html#3.4.0
> for a way to see how everything is packaged.
>
> eg: myrails.exe --eee-justextract
>
> -- Tom Jordan
>
> --
> "Nothing will ever be attempted, if all
> possible objections must first be
> overcome." - Samuel Johnson
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
speechexpert
2005-Sep-25 04:06 UTC
Re: How to make your Rails into an exe for windows, linux, mac
Dear choonkeat et al,
I made an application.exe along the lines I described, *except* when I move it
to another machine and try to run it, it gives
an error like:
script/server:3in ''require'': No such file to load -- webrick
(Load error) from script/server:3
Note: It runs fine on a machine with Ruby/Rails installed, The problem only
happens on a machine with no Ruby...
init.rb has line:
system ''ruby script/server''
It seems that webrick is not available and that the program may not include
it...
Any ideas? Do you check on computers without Ruby/Rails installed?
-John
----- Original Message -----
From: choonkeat
To: tdjordan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Cc: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
Sent: Monday, September 19, 2005 1:04 AM
Subject: Re: [Rails] How to make your Rails into an exe for windows, linux,
mac
Thanks for the great tip on --eee-justextract. missed that important option.
:-D
I''d met a very inconvenient warning trying to run Rails as a
(windows) desktop app since the produced exe runs off a temp dir.. Most
personal/desktop firewall (including microsoft''s) will prompt a
"block / allow ruby.exe" everytime I run my EXE. This is un-desirable.
At most, the warning should only come up once.
What I did,
1.. Create ${RAILS_ROOT}/init.rb
a.. I copied and modified the ${RAILS_ROOT}/scripts/server into
${RAILS_ROOT}/init.rb
b.. optionally, ${RAILS_ROOT}/init.rb can simply contain only "system
''ruby scripts/server''"
2.. tar2rubyscript ${RAILS_ROOT}
3.. rubyscript2exe ${RAILS_ROOT}.rb
4.. ${RAILS_ROOT}.exe --eee-justextract
5.. Copy the new 4 files + 3 folders somewhere, this will be my
${BUNDLE_DIR}
a.. empty.rb
b.. bootstrap.rb
c.. app.eee
d.. eee.exe
e.. app/
f.. lib/
g.. bin/
6.. Copy everything in ${RAILS_ROOT} into ${BUNDLE_DIR}/app
7.. Create ${BUNDLE_DIR}/run.bat
cd app
..\bin\ruby.exe -I ..\lib init.rb
Also, without the temp folder constraint and my files won''t be
deleted after every run:
1.. my sqlite db can be located safely within the ${BUNDLE_DIR}/app/db
folder, instead of / root folder
2.. there''s no more Permission denied - sqlite.dll errors on
closing the app
So, my distribution will be a .zip file of ${BUNDLE_DIR}. Simply unzip and
execute "run.bat". At last, I''ve reached the Instiki-ish
no-step-3 goal :-D
Sweet!
PS: Bonus points, I can continue to tweak everything inside ${BUNDLE_DIR}/app,
maintain them via CVS, and execute "run.bat" to immediately test them.
Zip up ${BUNDLE_DIR} and its ready to be distributed.
On 9/16/05, Tom Jordan
<tdjordan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
Hi Choonkeat
On 9/15/05, choonkeat
<choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Hmm. doesn''t "system ''ruby
script/server''" mean the target machine running
> the EXE will now require ruby installed?... and thus defeating the
purpose
> of making it a standalone executable in the first place? correct me if
i''m
> wrong there.
No ruby does not need to be installed.
It''s packaged up inside the .exe
When the .exe is executed, everything is extracted and
the embedded eee.exe puts the relative path bin/ into the path.
see: http://www.erikveen.dds.nl/rubyscript2exe/index.html#3.4.0
for a way to see how everything is packaged.
eg: myrails.exe --eee-justextract
-- Tom Jordan
--
"Nothing will ever be attempted, if all
possible objections must first be
overcome." - Samuel Johnson
------------------------------------------------------------------------------
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
choonkeat
2005-Sep-27 10:17 UTC
Re: How to make your Rails into an exe for windows, linux, mac
No idea... I did test (after creating my EXE) by uninstalling Rails and Ruby on my machine and running the exe (successfully),... I''d also sent to a couple of my friends (one of whom is definitely not programmer) to gather feedback - they are able to run without a glitch Try the 7-steps "copy script/server as init.rb" method I''d mentioned previously.. when making your exe, ctrl-c and wait for webrick to shutdown at step #3.. Erm.. if it still doesn''t work.. run your exe with --eee-justextract argument, you should get some folders created, and you can look inside the "lib" folder to see if webrick is inside. Mine is. lib/webrick.rb lib/webrick/ lib/webrick/*.* On 9/25/05, speechexpert <speechexpert-rphTv4pjVZMJGwgDXS7ZQA@public.gmane.org> wrote:> > Dear choonkeat et al, > I made an application.exe along the lines I described, *except* when I > move it to another machine and try to run it, it gives > an error like: > script/server:3in ''require'': No such file to load -- webrick (Load error) > from script/server:3 > Note: It runs fine on a machine with Ruby/Rails installed, The problem > only happens on a machine with no Ruby... > init.rb has line: > system ''ruby script/server'' > It seems that webrick is not available and that the program may not > include it... > Any ideas? Do you check on computers without Ruby/Rails installed? > -John > > ----- Original Message ----- > *From:* choonkeat <choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > *To:* tdjordan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > *Cc:* rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Sent:* Monday, September 19, 2005 1:04 AM > *Subject:* Re: [Rails] How to make your Rails into an exe for windows, > linux, mac > > Thanks for the great tip on --eee-justextract. missed that important > option. :-D > > I''d met a very inconvenient warning trying to run Rails as a (windows) > desktop app since the produced exe runs off a temp dir.. Most > personal/desktop firewall (including microsoft''s) will prompt a "block / > allow ruby.exe" everytime I run my EXE. This is un-desirable. At most, the > warning should only come up once. > > What I did, > > 1. Create ${RAILS_ROOT}/init.rb > - I copied and modified the ${RAILS_ROOT}/scripts/server into > ${RAILS_ROOT}/init.rb > - optionally, ${RAILS_ROOT}/init.rb can simply contain only > "system ''ruby scripts/server''" > 2. tar2rubyscript ${RAILS_ROOT} > 3. rubyscript2exe ${RAILS_ROOT}.rb > 4. ${RAILS_ROOT}.exe --eee-justextract > 5. Copy the new 4 files + 3 folders somewhere, this will be my > ${BUNDLE_DIR} > - empty.rb > - bootstrap.rb > - app.eee > - eee.exe > - app/ > - lib/ > - bin/ > 6. Copy everything in ${RAILS_ROOT} into ${BUNDLE_DIR}/app > 7. Create ${BUNDLE_DIR}/run.bat > > cd app > > ..\bin\ruby.exe -I ..\lib init.rb > > > > Also, without the temp folder constraint and my files won''t be deleted > after every run: > > 1. my sqlite db can be located safely within the > ${BUNDLE_DIR}/app/db folder, instead of / root folder > 2. there''s no more Permission denied - sqlite.dll errors on closing > the app > > So, my distribution will be a .zip file of ${BUNDLE_DIR}. Simply unzip and > execute "run.bat". At last, I''ve reached the Instiki-ish no-step-3 goal > :-D > > Sweet! > > PS: Bonus points, I can continue to tweak everything inside > ${BUNDLE_DIR}/app, maintain them via CVS, and execute "run.bat" to > immediately test them. Zip up ${BUNDLE_DIR} and its ready to be distributed. > > > > On 9/16/05, Tom Jordan <tdjordan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi Choonkeat > > > > On 9/15/05, choonkeat <choonkeat-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hmm. doesn''t "system ''ruby script/server''" mean the target machine > > running > > > the EXE will now require ruby installed?... and thus defeating the > > purpose > > > of making it a standalone executable in the first place? correct me if > > i''m > > > wrong there. > > > > No ruby does not need to be installed. > > It''s packaged up inside the .exe > > When the .exe is executed, everything is extracted and > > the embedded eee.exe puts the relative path bin/ into the path. > > > > see: http://www.erikveen.dds.nl/rubyscript2exe/index.html#3.4.0 > > for a way to see how everything is packaged. > > > > eg: myrails.exe --eee-justextract > > > > -- Tom Jordan > > > > -- > > "Nothing will ever be attempted, if all > > possible objections must first be > > overcome." - Samuel Johnson > > > > ------------------------------ > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails