[Rails] View inheritance and rendering in engines

2013-10-11 Thread Linus Pettersson
Hi I'm creating a mountable admin engine (like Active Admin but not as advanced) using Inherited Resources. Let's call it AdminFoo. In my main app I mount it with mount AdminFoo::Engine, at: '/admin' in my routes file. Let's say I have the following structure in my engine: *AdminFoo* app - vie

[Rails] Re: Track views in Rails app

2013-08-18 Thread Linus Pettersson
Phil: > > > On Saturday, August 17, 2013 2:04:51 PM UTC-7, Linus Pettersson wrote: >> >> Hi >> >> Often when I build sites I need some way to track visits to specific >> pages. For instance I need to see what Artists are the most popular so I >> can l

[Rails] Track views in Rails app

2013-08-17 Thread Linus Pettersson
Hi Often when I build sites I need some way to track visits to specific pages. For instance I need to see what Artists are the most popular so I can let my users sort based on popularity. I have used the gem Impressionist before but recently I ran into major performance issues (see https://git

[Rails] Re: Order on join model

2013-08-09 Thread Linus Pettersson
Ok, this seem to work fine @user.liked_photos.order("likes.created_at DESC") Den fredagen den 9:e augusti 2013 kl. 10:55:39 UTC+2 skrev Linus Pettersson: > > Hi > > I have three models, User, Like and Photo. > A User can like many Photos and a Photo can have many Liker

[Rails] Order on join model

2013-08-09 Thread Linus Pettersson
Hi I have three models, User, Like and Photo. A User can like many Photos and a Photo can have many Likers. In my User model I have: has_many :likes, foreign_key: "liker_id", dependent: :destroy has_many :liked_photos, through: :likes Like model: belongs_to :liker, class_name: "User" belongs_to

[Rails] Re: Create lowercase index

2013-07-04 Thread Linus Pettersson
:developers, :name, using: 'btree') > > generates: > > CREATE INDEX index_developers_on_name ON developers USING btree (name) -- > PostgreSQLCREATE INDEX index_developers_on_name USING btree ON developers > (name) -- MySQL > > Note: only supported by PostgreSQL and MySQ

[Rails] Create lowercase index

2013-07-02 Thread Linus Pettersson
Hi I'm sorting some columns like this: MyModel.order("LOWER(column) ASC")... But these queries are quite slow. I'm on Postgres by the way. Does Rails support creating a lowercase index for these situations? I know Postgres has support for it and I guess I can create one like this (found on SO)

[Rails] Sidekiq on Heroku

2013-06-30 Thread Linus Pettersson
Hi I want to use Sidekiq to run some jobs in the background. The jobs will be created by the whenever gem (or similar) which creates a Sidekiq worker at a specific time. This worker will in turn create a few hundred Sidekiq jobs. So, I'm using Heroku and wonder if I need to use a separate worke

[Rails] Minitest mock or stub methods

2013-06-09 Thread Linus Pettersson
Hi I'm building a small library to use in my Rails app which interacts with a 3rd party API. It fetches artists and tracks. So I have: lib/my_lib.rb lib/my_lib/artist.rb lib/my_lib/track.rb To get an artist I do artist = MyLib::Artist.find("Oasis") Which returns an instance of Artist if it find

[Rails] Re: STI convert object to other object

2013-05-13 Thread Linus Pettersson
Ok, the solution was to not use #becomes and instead just set the type field explicitly before saving. //Linus Den måndagen den 13:e maj 2013 kl. 10:19:08 UTC+2 skrev Linus Pettersson: > > Hi > > I'm using STI and want to convert one object to the other. The reason to >

[Rails] STI convert object to other object

2013-05-13 Thread Linus Pettersson
Hi I'm using STI and want to convert one object to the other. The reason to why I'm using STI is that I have a report and a full report. First someone reports something and can only enter a few fields. Then and admin can convert this into a full report and fill out the full report. Using STI m

Re: [Rails] Roll your own authentication?

2013-05-07 Thread Linus Pettersson
vient to have everything done and tested for you in gems like Devise. Any other thoughts on this subject? Den tisdagen den 7:e maj 2013 kl. 03:56:33 UTC+2 skrev tamouse: > > On Mon, May 6, 2013 at 12:38 PM, Linus Pettersson > > wrote: > > Hi! > > > > I wat

[Rails] Roll your own authentication?

2013-05-06 Thread Linus Pettersson
Hi! I watched this video the other day: http://vimeo.com/39498553 where they argue that it may be a better idea to roll your own authentication solution using has_secure_password instead of using, for instance, Devise. I started a new project using Rails 4 today and need authentication. I'm th

Re: [Rails] Filter params with strong parameters

2013-03-08 Thread Linus Pettersson
Thank you. I thought strong params needed symbols. Cheers, Linus Den fredagen den 8:e mars 2013 kl. 10:35:13 UTC+1 skrev Jordon Bedwell: > > On Fri, Mar 8, 2013 at 3:27 AM, Linus Pettersson > > wrote: > > Hi > > > > I have an hstore field in my database wh

[Rails] Re: Filter params with strong parameters

2013-03-08 Thread Linus Pettersson
Got it myself! Splat operator to the rescue :) params.require(:foo).permit(*Foo::DOCUMENT_FIELDS.map(&:to_sym)) Den fredagen den 8:e mars 2013 kl. 10:27:50 UTC+1 skrev Linus Pettersson: > > Hi > > I have an hstore field in my database where I store a lot of different >

[Rails] Filter params with strong parameters

2013-03-08 Thread Linus Pettersson
Hi I have an hstore field in my database where I store a lot of different fields. I still want getters, setters and validations for my fields so I've created an array with the fields like this: DOCUMENT_FIELDS = %w[foo bar baz] Then I do some meta programming to create getters and setters:

[Rails] Create polymorphic resources

2013-02-28 Thread Linus Pettersson
Hi I have created a polymorphic association for comments since I need commenting functionality on several models. The issue is that when I create the comment in my Commets#create action, I really don't know what type the parent is of. So, let's say I have Foo, Bar and Comment. Comment have thi

[Rails] Fetch record based on many to many association

2013-02-20 Thread Linus Pettersson
Hi Let's say I have three models, Company, User and Entry (and a join model EntryParticipants). Company has many Users, a User has many Entries (Entries created by a User). Also, there is another many-to-many relationship between User and Entry (a User can participate in many entries and an Ent

Re: [Rails] belongs_to condition that checks the current user?

2013-02-18 Thread Linus Pettersson
s Or am I wrong? :) Den måndagen den 18:e februari 2013 kl. 11:24:04 UTC+1 skrev Linus Pettersson: > > That is true. I'll probably change this. > > This doesn't solve my problem though. I realize that I phrased myself a > bit odd in my first post I will clarify below.

Re: [Rails] belongs_to condition that checks the current user?

2013-02-18 Thread Linus Pettersson
raint for this on the relation itself to get the correct users automatically etc. Den måndagen den 18:e februari 2013 kl. 11:00:21 UTC+1 skrev Colin Law: > > On 18 February 2013 09:44, Linus Pettersson > > > wrote: > > Hi > > > > I have a model, let'

[Rails] belongs_to condition that checks the current user?

2013-02-18 Thread Linus Pettersson
Hi I have a model, let's call it entry, that belongs to a user. The user and the entry also belongs to a company. Can I add a condition on the belongs_to relations to check this? Something like: belongs_to :assigned_user, class_name: "User" , conditions: { company_id: company_id } This doesn'

[Rails] Re: Problem with many to many relationship

2013-02-08 Thread Linus Pettersson
Found the error... I have written t.belongs in one class instead of belongs_to Tired... Den fredagen den 8:e februari 2013 kl. 15:28:16 UTC+1 skrev Linus Pettersson: > > Hi > > I'm trying to create a many to many relationship between two models. > > A User can

[Rails] Problem with many to many relationship

2013-02-08 Thread Linus Pettersson
Hi I'm trying to create a many to many relationship between two models. A User can be associated with many Incidents and vice versa. class User < ActiveRecord::Base include ActiveModel::ForbiddenAttributesProtection has_many :incident_participants, foreign_key: "participant_id" has_many :

[Rails] Re: Error installing Rails

2013-02-05 Thread Linus Pettersson
First, install rbenv/ruby-build or RVM https://github.com/sstephenson/rbenv/ https://github.com/sstephenson/ruby-build or https://rvm.io/ Then install ruby 1.9.3 Then install rails Good luck! Den tisdagen den 5:e februari 2013 kl. 08:37:23 UTC+1 skrev Ruby-Forum.com User: > > Hi guys > > I'm

[Rails] Re: Create a helper for models and views?

2013-02-03 Thread Linus Pettersson
And actually, it is used in my controllers as well :) Den söndagen den 3:e februari 2013 kl. 13:23:28 UTC+1 skrev Linus Pettersson: > > Hi! > > If I have a method that is useful in both models and in views, where would > be the appropriate place to put it? > > The method i

[Rails] Create a helper for models and views?

2013-02-03 Thread Linus Pettersson
Hi! If I have a method that is useful in both models and in views, where would be the appropriate place to put it? The method in question just takes two dates as strings, tries to parse them and returns all dates in the range between them. It also takes care of the issues when the dates are ba

[Rails] Re: Count entries in postgresql grouped by date

2013-01-29 Thread Linus Pettersson
d_at.to_date } end And then just use visits[date].count for the counting. There will probably not be that many records anyway... Den tisdagen den 29:e januari 2013 kl. 17:26:00 UTC+1 skrev Linus Pettersson: > > Hi! > > I have a table with visits with a visited_at: attribute which i

[Rails] Count entries in postgresql grouped by date

2013-01-29 Thread Linus Pettersson
Hi! I have a table with visits with a visited_at: attribute which is a datetime field. They seem to be stored as UTC. Now I want to count all visits each day and return something like: { 2013-01-01: 8, 2013-01-02: 4, 2013-01-07: 9, ... } So, I did it like this which kind of works...:

[Rails] Best practice to handle this

2013-01-26 Thread Linus Pettersson
Hi! I have a model which has a field that can have three values only. I store the value in the database as an integer, 0, 1 or 2, but when I display it I want a more appropriate text. And, I want it to be translatable using i18n. Let's say that it corresponds to how difficult something is. So,

[Rails] Re: Pass data to javascript

2013-01-25 Thread Linus Pettersson
Another option would be to fetch the raw JSON data using javascript from .../events.json and then do the grouping and whatever client-side and pass to the graph... Maybe too inefficient? // Linus Den fredagen den 25:e januari 2013 kl. 10:35:40 UTC+1 skrev Linus Pettersson: > > Hi! &

[Rails] Pass data to javascript

2013-01-25 Thread Linus Pettersson
Hi! I'm creating a bar graph using Morris.js. What I'm showing in the graph is dates on the X-axis and the number of times an event has occurred on that date on the Y-axis. So, I followed Ryan Bates episode on Morris.js: http://railscasts.com/episodes/223-charts-graphs-revised (It's a PRO epi

[Rails] Use Rails 4 now?

2013-01-05 Thread Linus Pettersson
Hi! If I'm starting to develop a website soon, would you recommend me to use Rails 4? I guess a release is not THAT far away, so it will probably be released before my site is done... So, start with rails 4 or use 3.2 and upgrade later? How stable is rails 4 atm? Cheers! Linus -- You receiv

[Rails] Re: Problem passing id of parent model to child

2012-11-01 Thread Linus Pettersson
What path do you get? It should be something like "/organizations/:id/projects/new". This is where you can add a form for example to add a new project. Do you try to POST to that path above? If so, that's wrong (it's for GET requests). Read more about nested resources here: http://guides.rubyon

Re: [Rails] Remove test_unit

2012-08-28 Thread Linus Pettersson
file remove the line: > > require 'rails/all' > > and include only the railties you need excluding test unit > > Regards. > > 2012/8/28 Linus Pettersson > > >> Hi! >> >> I have an app that uses Rails 3.2.7. I want to use minitest-rails ( >> http

[Rails] Remove test_unit

2012-08-28 Thread Linus Pettersson
Hi! I have an app that uses Rails 3.2.7. I want to use minitest-rails (https://github.com/blowmage/minitest-rails) instead of test_unit. I have installed it and it works fine. The problem is when I generate something, say a model, it still uses the test_unit generators and NOT minitest. So, I

[Rails] Are you using any CMS or simply building from scratch?

2012-07-31 Thread Linus Pettersson
Hi! When I'm creating an application for a project of my own I usually use Active Admin or something for my admin area and code everything else myself. The backend interface is not always perfect but it's OK because only I will use it. The few quirks and weird stuff is OK because I know how ev

Re: [Rails] Redirect to a 3rd party website

2012-07-29 Thread Linus Pettersson
My bad, it does NOT work! Den söndagen den 29:e juli 2012 kl. 20:04:14 UTC+2 skrev Linus Pettersson: > > Actually, I think I found a solution now. > > I first parse it, like: > uri = URI.parse(the_url) > and then: > redirect_to uri.to_s > > > Works :) > > >

Re: [Rails] Redirect to a 3rd party website

2012-07-29 Thread Linus Pettersson
Actually, I think I found a solution now. I first parse it, like: uri = URI.parse(the_url) and then: redirect_to uri.to_s Works :) Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder: > > On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson > wrote: > &

Re: [Rails] Redirect to a 3rd party website

2012-07-29 Thread Linus Pettersson
I mean, URI.parse(uri) doesn't return any error on either of the URIs it seems. Den söndagen den 29:e juli 2012 kl. 19:44:48 UTC+2 skrev Linus Pettersson: > > Thank you for your time. > > How can I check if the URL is "good" or needs to be encoded? > > Best R

Re: [Rails] Redirect to a 3rd party website

2012-07-29 Thread Linus Pettersson
Thank you for your time. How can I check if the URL is "good" or needs to be encoded? Best Regards Linus Den söndagen den 29:e juli 2012 kl. 19:30:58 UTC+2 skrev Hassan Schroeder: > > On Sun, Jul 29, 2012 at 10:09 AM, Linus Pettersson > wrote: > > > I need t

[Rails] Re: Getting error while starting server plz help

2012-07-29 Thread Linus Pettersson
rails -v in console. Den söndagen den 29:e juli 2012 kl. 19:08:58 UTC+2 skrev Ruby-Forum.com User: > > How can I confirm that kind let me know > > -- > Posted via http://www.ruby-forum.com/. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Tal

[Rails] Redirect to a 3rd party website

2012-07-29 Thread Linus Pettersson
Hi! I need to redirect to some 3rd party websites. The issue is that some of the urls works to redirect and some doesn't work, using redirect_to url Example 1: http://example.com/click?a(999)p(999)prod(99)ttid(999)url(http%3A%2F%2Fwww.someothersite.se%2Fd%2FBLah-Fooo%2FBar%2F_%2FA-3z

[Rails] Re: Rails' inflections are messy

2012-07-19 Thread Linus Pettersson
At least they should fix the ones that are incorrect... "Octopus".pluralize should return "Octopuses" and NOT "Octopi"... :) Den torsdagen den 19:e juli 2012 kl. 20:23:15 UTC+2 skrev davidcelis: > > > > On Thursday, July 19, 2012 11:22:40 AM UTC-7, davidcelis wrote: >> >> For anybody who shares

[Rails] Re: Create a select tag including related models

2012-06-19 Thread Linus Pettersson
No...but that's generating the same as grouped_collection_select() but without the wrapping tag so that doesn't work... Den tisdagen den 19:e juni 2012 kl. 19:55:43 UTC+2 skrev Ruby-Forum.com User: > > Linus Pettersson wrote in post #1065179: > > Hi! > >

[Rails] Create a select tag including related models

2012-06-19 Thread Linus Pettersson
Hi! I have categories and subcategories. Now I want to create a select tag with this data so a user can select either a category or a subcategory. What I tried first was to use grouped_collection_select and use the main categories as groups and list the subcategories inside. Visually, this is

[Rails] Re: return JSON in AJAX

2012-06-17 Thread Linus Pettersson
You can read more about rendering JSON here: http://guides.rubyonrails.org/action_controller_overview.html#rendering-xml-and-json-data Den söndagen den 17:e juni 2012 kl. 20:17:32 UTC+2 skrev Ruby-Forum.com User: > > Thank you guys for the answer, but I just did this: > > render :json => Active

[Rails] Re: A simple csv import function to my Rails application

2012-06-10 Thread Linus Pettersson
Have you added *require* 'csv' ? Den lördagen den 9:e juni 2012 kl. 19:07:49 UTC+2 skrev Ruby-Forum.com User: > > Colin Law wrote in post #1063851: > > On 9 June 2012 16:42, Anders Andrew wrote: > >> I am quite new to Rails, so nothing fancy. Preferably some basic code > in > >> View, Cont

[Rails] Re: parentheses vs braces

2012-04-25 Thread Linus Pettersson
u.update_attributes(...) is a method and you give it a hash as parameter u.attributes = ... just assigns the attributes variable with a hash. Den onsdagen den 25:e april 2012 kl. 21:15:36 UTC+2 skrev Ruby-Forum.com User: > > So why the = sign in the first example? > > -- > Posted via http://w

[Rails] Re: Asset - Pipeline

2012-04-11 Thread Linus Pettersson
To run the first code you tried you need to add the .erb extension. Otherwise, it's like running ruby code in a css/html file or whatever. It doesn't work :) The assets pipeline works like this: example.css.scss => Interprets scss first and serves the css file. example.html.erb => interprets erb

Re: [Rails] Ideas on a project or gem to develop

2012-04-08 Thread Linus Pettersson
ou a > project idea, and i'd be happy to help. > > Alecs > > > On Apr 5, 2012, at 7:20 PM, Linus Pettersson wrote: > > ity student (Masters) and this summer I will probably not have an ordinary > summer job, but instead work on some of my own projects. These will

[Rails] Ideas on a project or gem to develop

2012-04-05 Thread Linus Pettersson
Hi! I'm a swedish university student (Masters) and this summer I will probably not have an ordinary summer job, but instead work on some of my own projects. These will probably not fill my time so now I want some ideas for a project to start or a gem to develop in Rails. Do you have any servic

Re: [Rails] Create a nested form.

2012-04-04 Thread Linus Pettersson
> > Is_A and Has_A relationships. Describe the relationship between the forms > > > On 4 April 2012 14:42, Linus Pettersson <> wrote: > >> Hi! >> >> I have created a nested form and now I want to make it dynamic. I have >> two models, "Appli

[Rails] Dynamic forms

2012-04-04 Thread Linus Pettersson
Hi! I have a nested form with Applications and Participants. One application can have many participants. Now I want to be able to dynamically (using JS) add fields for the Participants in the Applications form. I'm a bit lost on how to do it though... I did watch some videos on RailsCasts (#196

[Rails] Create a nested form.

2012-04-04 Thread Linus Pettersson
Hi! I have created a nested form and now I want to make it dynamic. I have two models, "Applications" and "Participants". Each application may have several participants, but at least one which is the contact person. An issue that I have is that when the form is not validated it renders the par

[Rails] How to set up these associations and nested form

2012-03-31 Thread Linus Pettersson
Hi! I'm creating a simple signup form where people can sign up for a camp. They should be able to add a contact person and also sign up other people (such as family members). Two models: Application has_many :participants accepts_nested_attributes_for :participants Participant belongs_to

[Rails] Re: customise the color of link_to text

2012-02-29 Thread Linus Pettersson
Well a link_to creates a regular link in HTML so you need to style the a tag. #table-3 th a { color: . } Or if you want to style both regular text and links in that part: #table-3 th, #table-3 th a { color: ... } Den onsdagen den 29:e februari 2012 kl. 19:16:51 UTC+1 skrev Ruby-Forum.c

[Rails] Re: Rails with Ajax

2012-02-13 Thread Linus Pettersson
Yes, but the code in the search view is not executed again when the AJAX request is fired :) So, you have to do the check in your loader.js.erb and not the search view. Something like this should work: <% if @group_trace %> $('#loader_div').html("<%=j render(@group_trace)%>"); <% end %> Cheers

Re: [Rails] update_attribute on a specific record

2012-02-10 Thread Linus Pettersson
Yep, or: Photo.find(123).update_attribute(:title => "New great title") Regards -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/-0h5vJWe_s4J. To

[Rails] Re: Rails with Ajax

2012-02-09 Thread Linus Pettersson
Well, the code in the search view is executed when the view is rendered. It is not executed again when you inject the html using javascript. So the if @group_trace code is only executed when the search view is rendered and @group_trace is not created yet. What are you actually trying to achieve

[Rails] Re: Rails with Ajax

2012-02-08 Thread Linus Pettersson
Well, you go here, right? yourapp.com/search ? Then the @group_trace is nil because it's not created until you run the loader action. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://grou

[Rails] Re: How to migrate from md5 to bcrypt?

2012-01-28 Thread Linus Pettersson
Is that even possible? I don't think so... I'd say that the best way is to reset all the passwords, notify them and allow them to change it. Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit

Re: [Rails] Re: Optimizing query

2012-01-26 Thread Linus Pettersson
This query is only to get the appropriate Categories & Subcategories. There are 5 Categories and 45 Subcategories. My products are imported from webshops which are using different categories for the same things ("tshirt", "t-shirts", "t-shirt", "short sleeved shirts" may all be the same). To co

Re: [Rails] Re: Optimizing query

2012-01-26 Thread Linus Pettersson
Also, another reason for the query that I forgot to mention is that if a user filters the products for female products only for instance, it should only show categories and subcategories that contains products for that gender. The gender is specified in the products table... -- You received t

Re: [Rails] Re: Optimizing query

2012-01-26 Thread Linus Pettersson
Hi I tested to remove the .order(...) part and indeed, the query time goes down to ~100ms. However, it doesn't help to add indices, at least not as I did :) add_index :categories, :name add_index :subcategories, :name Did some more testing and if I keep the .order... but don't join the produc

Re: [Rails] Re: Optimizing query

2012-01-25 Thread Linus Pettersson
Well, maybe it's not necessary... It is the slowest of my queries as far as I can see anyway. I'm using Rails 3.2 and I have enabled automatic EXPLAIN on slow queries (>0.5s). This query is currently being "explained" in my console when I run it on my localhost. "SQL (556.5ms) ..." 556.5ms see

[Rails] Re: Optimizing query

2012-01-25 Thread Linus Pettersson
Thank you. I have added the generated SQL to the snipt in my first post. Regarding the EXPLAIN ANALYZE, can I somehow run that on Heroku? I'm using their shared database so I don't have access to any psql console... I did run it on my local machine though. The thing is that it differs in databa

[Rails] Optimizing query

2012-01-25 Thread Linus Pettersson
Hi! I'm trying to speed up some queries in my app, running Rails 3.2 and need some help. I'm running the app at Heroku on postgresql. I'm new to postgresql and need some help to optimize a query so it effectively uses indices. This is the query I'm currently working on: http://snipt.net/Linuus

Re: [Rails] Re: RailsCasts

2012-01-13 Thread Linus Pettersson
That is correct. The .js (or .js.coffee if using coffeescript) files should be in app/assets/javascript/. You could use require tree which is specified from the beginning and will include all javascript files. I do prefer to require each file separately though as it gives me more control. Chee

[Rails] Re: RailsCasts

2012-01-12 Thread Linus Pettersson
As it says in application.js: " // This is a manifest file that'll be compiled into including all the files listed below. // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically // be included in the compiled file accessible from http://example.com/assets

Re: [Rails] Complex query with multiple joins

2012-01-07 Thread Linus Pettersson
Hi again! I posted a question about this issue on StackOverflow and got an interesting response. To force Rails to join the included table you can use eager_load() instead of includes(). Using eager_load() and removing the group() seems to make my query work perfect. Correct version: Category

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Wow! Thank you for all the help Peter! I really appreciate it. I will test that code tomorrow as it's getting quite late here. I did a small test now though. It seems that you can't mix joins and includes. This doesn't work: Category.includes(:subcategories).joins("INNER JOIN resellercategories

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Hi Colin! Absolutely. You mean for the models? Here they are: http://snipt.net/Linuus/category-and-subcategory?key=38ba590408ac4233927a06046eeca30d Best Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discuss

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Still doesn't work :( Generated SQL: " SELECT "categories".* FROM "categories" INNER JOIN resellercategories AS r ON subcategories.id = r.subcategory_id INNER JOIN products AS p ON r.id = p.resellercategory_id WHERE (p.gender = 'unisex' OR p.gender = 'male') AND (subcategories.id > 0) GROUP BY

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
(I wrote an answer before but it seems to not have been published so here we go again :) ) No, there is no LEFT OUTER JOIN subcategories... I guess this is because I don't have any condition on the subcategories. Then it will execute two queries instead of using the LEFT OUTER JOIN. I just ran

[Rails] Re: How to pass a field from simple_form as a hidden div value

2012-01-06 Thread Linus Pettersson
You have to use Javascript for that. Why do you want to do this anyway? If you just want to combine "First" and "Last" to one string "First Last", do it when you receive the data in the controller or model. Regards Linus -- You received this message because you are subscribed to the Google Gr

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Also, just to be clear. You are totally right that I just do "mc.subcategories.each"... This is what the view looks like: http://snipt.net/Linuus/categories-view-1?key=8f1be321f6253bd74847066a719490ce Regards Linus -- You received this message because you are subscribed to the Google Groups "R

Re: [Rails] Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Thank you Peter. I also found the related section in the rails guides about this: http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations However, I haven't gotten it to work just yet. The above example you wrote doesn't work because that subcategories.id is not pre

[Rails] Re: Complex query with multiple joins

2012-01-06 Thread Linus Pettersson
Man, I'm beating my head against this one... The query above is probably not the best. Any other suggestions? Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.

[Rails] Complex query with multiple joins

2012-01-05 Thread Linus Pettersson
Hi! I have an app that manages products. I import the products from several resellers and they all name their categories different. Because of this I have resellercategories that are mapped to my own subcategories. Categories - Subcategories (belongs_to Category) Resellercategories (belongs_to

Re: [Rails] Update related items on save?

2012-01-03 Thread Linus Pettersson
Thank you. I got the scopes working so now I can skip the extra field :) Best Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_4K

Re: [Rails] Update related items on save?

2012-01-03 Thread Linus Pettersson
Thank you Peter. I have some follow up questions. Let's say I would use a scope. How could I do that? (let's ignore the "image_small" for now and focus on the subcategory) There is nothing in the product table that I can use to select the completed products. It is only regarded as completed if

[Rails] Update related items on save?

2012-01-03 Thread Linus Pettersson
Hi! I have an app with products, categories, subcategories and resellercategories. Products belongs_to :resellercategory has_one :subcategory, :through => :resellercategory has_one :category, :through => :subcategory So, there are a lot of resellercategories that are (manually) mapped to m

Re: [Rails] Check whether you migrate up or down in Rails 3.1?

2012-01-02 Thread Linus Pettersson
I see. Thank you very much Peter! Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/H8RtP69UakQJ. To post to this group, send email

[Rails] Ordering on Heroku and special characters (å ä ö)

2012-01-02 Thread Linus Pettersson
Hi! I just pushed an app to Heroku for the first time. I notice that the ordering is not quite correct. It is on my local machine though. The issue is that the swedish characters Å Ä and Ö are ordered like A A and O. I guess this is because some collation or locale is wrong. Any ideas on how to

[Rails] Check whether you migrate up or down in Rails 3.1?

2012-01-02 Thread Linus Pettersson
Hi! In Rails 3.1 there is only one method for migrations called 'change'. I want to run some code in a migration only when migrating up, not down. Is that possible? The issue I have is that this code is inside a migration file from Active Admin: # Create a default user AdminUser.create!(:emai

[Rails] Re: How can I display model validation error in view page separately beside each form field

2012-01-02 Thread Linus Pettersson
You could use formtastic. It uses inline error messages for the fields. https://github.com/justinfrench/formtastic Also, it's awesome :) Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web vi

Re: [Rails] Using Rspec, factory_girl and permalink?

2012-01-02 Thread Linus Pettersson
Of course... Thank you! Sometimes when you've looked for too long on the code you get blind :) Regards Linus -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyo

[Rails] Using Rspec, factory_girl and permalink?

2011-12-29 Thread Linus Pettersson
Hi! I'm using Rspec and factory_girl. In my products model I have a method that creates permalinks simply by overriding to_param, like this: def create_permalink self.permalink = "#{self.name} #{self.brand.name}".parameterize end My product factory looks like this: Factory.define :product do

[Rails] Convert html entities? Just use html_safe?

2011-12-18 Thread Linus Pettersson
Hi! I'm importing lots of products via XML. Some characters like the swedish å, ä, ö are encoded as å for instance. When I print it I just append .html_safe to make it appear correct. Is this a good and safe approach or should I convert the characters in some other way? -- You received this

[Rails] Re: Select_tag don't "save" the values

2011-12-11 Thread Linus Pettersson
You need to get the current value from the params hash. Something like this: <%= select_tag :gender, options_from_collection_for_select(@genders, "value", "name", params[:gender]), :include_blank => true %> Notice the params[:gender]. Regards Linus -- You received this message because you are

[Rails] Re: Handle categories and (nested) resources

2011-12-02 Thread Linus Pettersson
Maybe it is better to just create two models/controllers and nest them? That way I get restful routes easily. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyo

[Rails] Handle categories and (nested) resources

2011-12-02 Thread Linus Pettersson
I have an application, built with Rails 3.1.3, that has products and categories. The categories are related to other categories, so a category can be a parent or a child category. The products are then related to a child category. Now, I'm thinking about how I should define the routes. Is it a

Re: [Rails] Upgrade to rails 3.1.3

2011-11-25 Thread Linus Pettersson
Ok, thank you guys. Hasn't some other gems changed? Like some of these: gem 'sass-rails', '~> 3.1.4' gem 'coffee-rails', '~> 3.1.1' gem 'uglifier', '>= 1.0.3' Are these still the default in 3.1.3? Regards Linus -- You received this message because you are subscribed to the Google Groups "Rub

[Rails] Upgrade to rails 3.1.3

2011-11-24 Thread Linus Pettersson
Hi! The app that I'm developing is based on Rails 3.1.1. Now 3.1.3 has been released. I'm a bit new to rails so I'm not sure how to safely do the upgrade. - How do I upgrade my app from Rails 3.1.1 to 3.1.3? Regards Linus -- You received this message because you are subscribed to the Google

[Rails] Re: Trigger AJAX form submit on change

2011-11-24 Thread Linus Pettersson
Yes, of course. This was only in an Admin interface where I will need to quickly select a dropdown only for each post. It is very tedious to select and then click a button when you might need to do it like a couple of thousand times :) I use Active Admin which comes with an old jQuery / rails j

[Rails] Trigger AJAX form submit on change

2011-11-23 Thread Linus Pettersson
Hi! I have a small form that I want to submit through AJAX when a dropdown is changed. I have set the form to be :remote => true. But if I do something like: $('.element').change -> this.form.submit() The form is not submitted through AJAX. Can I trigger Rails ajax submit function someho

Re: [Rails] How to structure my database

2011-11-19 Thread Linus Pettersson
Thank you for the answer! Yes, I was thinking about just having the reseller categories (raw categories) as a lookup table. So for each product I import I just check what category it should be in. One issue with this is that it might get a bit messy if I would change the relations between a res

[Rails] How to structure my database

2011-11-18 Thread Linus Pettersson
Hi! I'm creating an app that will import products from several XML feeds. In the XML there is a category specified, like T-Shirt for instance. The problem is that different resellers specify the categories differently. For instance, what one reseller calls "T-Shirts" another may call "T-Shirt",

[Rails] Ang.: Re: Ang.: Re: Add virtual attribute

2011-08-01 Thread Linus Pettersson
Well, yes but that's not the point. Items have a status field. Lists has many items. When displaying a List as JSON I want it to have an attribute that counts how many finished items there are in the list and how many unfinished items there are in the list. The above methods only fetches the ite

Ang.: Re: [Rails] Add virtual attribute

2011-07-31 Thread Linus Pettersson
I already have done that, like this: def unfinished_items self.items.where("status = ?", false) end def finished_items self.items.where("status = ?", true) end So I can use the List.unfinished But how do I add it as attributes to the json output? -- You received this message b

  1   2   >