ruby-on-rails-3

PostgreSQL query works locally (9.x), but gives syntax error on Heroku (8.x)

陌路散爱 提交于 2019-12-25 08:14:16
问题 I developed my site and it works like a charm on my local machine. The query is supplied by a fellow Stackoverflow member in this thread. schema.rb portion that is relevant Same data locally as on Heroku. select * from ( select * , row_number() over (partition by odds_type order by odds_index desc) as rn2 from ( select * , row_number() over (partition by event_id, bookmaker_id, odds_type order by created_at desc) as rn1 from Odds where event_id = #{e.id} ) sub1 where rn1 = 1 ) sub2 where rn2

Weird looping behaviour - what's happening here?

孤人 提交于 2019-12-25 08:10:38
问题 Gotten myself all confused with what I think is a double loop and don't know how to fix it. Can anyone save me from going completely mad please? This works in my show view: <% @releases_tracks_temp.each do |releases_track| %> <tr> <td><%= releases_track.track.id %> / <%= releases_track.position %></td> <td><%= releases_track.track.name %> <%= releases_track.track.artists.map { |a| a.name}.join (", ") %></td> <td><%= releases_track.track.isrc %></td> <td><%#= link_to image_tag("icons/delete

Rails 3: undefined method messages for Folder

≡放荡痞女 提交于 2019-12-25 08:04:23
问题 I'm running Rails 3 and like to have a message system. Here is the tutorial for it: http://www.novawave.net/public/rails_messaging_tutorial.html It's for Rails 2 so I was trying to implement it in Rails 3. Everything went fine and i can send messages. But when i like to check my inbox this error shows up: undefined method `messages' for #<Folder:0x0000010419fd48> Mailbox Controller: class MailboxController < ApplicationController def index redirect_to new_session_path and return unless logged

How to I serve data from an object's associations in rails forms?

你离开我真会死。 提交于 2019-12-25 07:48:28
问题 I have an object that I am developing a controller for that has many attributes. However, due to the data model I have created, most of the attributes that I have to edit are saved through associations in other tables. EG: I have articles that have tags through a taggings table (and about 20 other attributes saved in other tables). THe article has many other attributes through polymorphic associations etc.. The associations work great, and enable the saving of multiple entries of each

Rails erb preprocessing not happening in development mode

こ雲淡風輕ζ 提交于 2019-12-25 07:38:10
问题 For whatever reason, this first attempt at dynamic styling gets me a Sass::SyntaxError on the line below. It looks like the erb is not being pre-processed. /* app/assets/stylesheets/variables.css.scss.erb */ $headerHeight: <%= '15px' %>; It's in development mode. Any idea what could cause this? Here are my configuration options relating to assets in case that helps: # Application config.assets.enabled = true config.assets.initialize_on_precompile = true config.assets.version = '1.1' #

Rails 3, checked radio button with if function

馋奶兔 提交于 2019-12-25 07:35:11
问题 I have a radio button within my form as follows <div class="btn-group" data-toggle="buttons-radio"> <%= f.radio_button :start_year, :class=> "btn", :value=> '2007' %> 2007 <%= f.radio_button :start_year, :class=> "btn", :value=> '2008' %> 2008 <%= f.radio_button :start_year, :class=> "btn", :value=> '2009' %> 2009 </div> I am using twitter bootstrap I want to do something like the following: <div class="btn-group" data-toggle="buttons-radio"> <%= f.radio_button :start_year, :class=> "btn",

How can I get the datatype of an attribute from a Rails model?

空扰寡人 提交于 2019-12-25 07:29:44
问题 I am using Postgres in a Rails project and I have discovered that I need to change all of my varchar datatypes to citext . Rather than do this by hand, I want to just create a migration that loops through all of the models and their attributes and converts them as necessary. Most of these models are empty, so it's not a matter of instantiating them. I need to find out if ActiveRecord "knows" what the datatype of its corresponding database column is. 回答1: @model.column_for_attribute('title')

How to calculate a record's ranking compared to others based on a single column in Rails? [closed]

僤鯓⒐⒋嵵緔 提交于 2019-12-25 07:25:11
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . Assuming I have User model with a column called point . How can I get an instance's ranking compared to all other User rows. 回答1: The user's rank can be thought of as the number other users with more points than them, plus 1. As Mischa pointed out in the comments, an appropriate place for this

Persisting form input over login

蹲街弑〆低调 提交于 2019-12-25 07:24:48
问题 I have this app where a user can write a review for a school. A user must sign in with Facebook to save a review. The problem is if a user is unsigned and writes a review, then signs in with Facebook they have to write the same review again. I am trying to fix this by storing the review data form in sessions, but I cant quite make it work. What is the proper rails way to do this? ReviewForm: <%= form_for [@school, Review.new] do |f| %> <%= f.text_area :content %> <% if current_user %> <%= f

Database driven content printing its full DB string to page when no code told to do so?

。_饼干妹妹 提交于 2019-12-25 07:20:57
问题 I'm just making a newsfeed that is database driven, right now I have it working, but at the end of every news post, I get a string like so: 21 <div id='newsfeed'> 22 <%= @news.each do |new| %> 23 <div class='span10'> 24 <h3><%= new.title %></h3> 25 <p class='muted'><%= new.date %></p> 26 <p><%= new.body %></p> 27 </div> 28 <% end %> 29 </div> 30 </div> and then my controller has this: def home @news = Newsfeed.all end Yet the output looks like this: It would work great if it didn't post the