ruby-on-rails-3

ActiveRecord::RecordNotFound in PostsController#show clicking a link

£可爱£侵袭症+ 提交于 2020-01-05 09:12:50
问题 <li><%= link_to('More Commented', posts_morecommented_path) %></li> Error ActiveRecord::RecordNotFound in PostsController#show Couldn't find Post with id=morecommented Request Parameters: {"id"=>"morecommented"} Where am I doing the mistake? postscontroller#show action def show @post = Post.find(params[:id]) ... end morecommented.html.erb <% @moreCommented.each do |t| %> <%= link_to t.title, :controller => '/posts', :action => 'show', :id => t.id %><br/> <% end %> rake routes post GET /posts/

jobs is not firing on heroku using hirefire

主宰稳场 提交于 2020-01-05 08:43:16
问题 i'm using gem "delayed_job_active_record" with hire fire on heroku to run jobs in background.i have also set heroku envirnoment variable using my heroku account. My sequence in gem file is below gem 'delayed_job_active_record' gem 'daemons' gem 'hirefire' it is working in local envirnoment in development as production as well. But jobs not firing on heroku from delayed job table. First i try with no config file hirefire.rb in intilizer but no succes. After i add and put this code below.

Pass a parameter from view to a scope defined in the model

我只是一个虾纸丫 提交于 2020-01-05 08:30:04
问题 Im refactoring my code and try to follow the convention "Skinny controllers, fat models" Now i tried to move a Query to the model: scope :scope1_department, where(sender_username: params[:username], recipient_username: params[:username]) scope :scope2_department, where(recipient_username: params[:username]) scope_department = scope1_department.merge(scope2_department).sort_by(&:created_at) And in my controller i have: @messages = Message.scope_department(params[:username]) Now i get this

Difference between rails label and label_tag

徘徊边缘 提交于 2020-01-05 08:28:54
问题 In rails both label and label_tag seem to work the same. Are there any internal differences on how they are rendered by rails ? And which one is a better to use ? 回答1: Use f.label when you are inside a form object created with form_for(...) do |f| and want to refer to a model-attribute. If your app is i18n-ed, Rails will use the translation to display the attribute name. Use label_tag when you are not in a form object. (Or you are in a form object but want to create a dummy label for a non

Rails 3 - Make a “link_to” using selected value from collection select

只愿长相守 提交于 2020-01-05 08:13:23
问题 Hello everyone. I have a form in my rails 3 app, and one of the fields is a "collection select" like this <div class="field"> <%= f.label :provider_id, "Provider" %> <%= collection_select( :purchase_document, :provider_id, Provider.all, :id, :name) %> </div> The idea, is to be able to add a "link_to" using the selected value from the "collection select" i.e.: <div class="field"> <%= f.label :provider_id, "Provider" %> <%= collection_select( :purchase_document, :provider_id, Provider.all, :id,

Unable to install Nokogiri

ε祈祈猫儿з 提交于 2020-01-05 08:11:45
问题 When I run sudo gem install nokogiri on Ubuntu 12.1, I'm returned with this. What's wrong and how do I fix it? jason@jason:~/ror/clss$ sudo gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require

Rails 3: Trying to extend Action Mailer with a module

守給你的承諾、 提交于 2020-01-05 08:11:32
问题 Trying to rewrite an old alias_method_chain to add a filter on outgoing emails, and it isn't working. I'm pretty sure I've leaving something out/missing something, but I don't know what. This file is in /lib/outgoing_mail_filter.rb, which is loaded with config/initializers/required.rb Here's the old code that worked under Rails 2: class ActionMailer::Base def deliver_with_recipient_filter!(mail = @mail) unless 'production' == Rails.env mail.to = mail.to.to_a.delete_if do |to| !(to.ends_with?(

How to access virtual attributes of model in a nested form with Rails

老子叫甜甜 提交于 2020-01-05 08:10:19
问题 I have a basic nested form. I want to access a virtual attribute for the nested form's model. Model 1: Lease Has_many :transactions accepts_nested_attributes_for :transactions, :reject_if => lambda { |a| a[:dated].blank? }, :allow_destroy => true ... Model 2: Transaction belongs_to :lease def balance_to_date(aDate) #Returns the current balance up to aDate ... end ... In the nested form I want to put something like: <td style="width:100px;"><%= nested_f.text_field :dated, size: 8 %> </td> <td

How to render a partial from controller after making an ajax call

我只是一个虾纸丫 提交于 2020-01-05 08:04:58
问题 I am trying to render a partial after I make an AJAX request to a method in my controller. Here is my current AJAX call: $('.savings_link').click(function(event){ $.ajax({ type: 'GET', url: '/topics/savings_easter_egg', data: { savings: data[key]['saving'] } , dataType: 'json', }); event.preventDefault(); // Prevent link from following its href }); This call currently works and it hits my controller method where I try to return and render a partial. def savings_easter_egg @savings = params[

Issues with DISTINCT when used in conjunction with ORDER

≯℡__Kan透↙ 提交于 2020-01-05 07:55:22
问题 I am trying to construct a site which ranks performances for a selection of athletes in a particular event - I have previously posted a question which received a few good responses which me to identify the key problem with my code currently. I have 2 models - Athlete and Result (Athlete HAS MANY Results) Each athlete can have a number of recorded times for a particular event, i want to identify the quickest time for each athlete and rank these quickest times across all athletes. I use the