ruby-on-rails-3.2

Where to put Ruby helper methods for Rails controllers?

流过昼夜 提交于 2019-11-27 18:55:01
I have some Ruby methods certain (or all) controllers need. I tried putting them in /app/helpers/application_helper.rb . I've used that for methods to be used in views. But controllers don't see those methods. Is there another place I should put them or do I need to access those helper methods differently? Using latest stable Rails. You should define the method inside ApplicationController . John Cleary For Rails 4 onwards, concerns are the way to go. There is a decent article here http://richonrails.com/articles/rails-4-code-concerns-in-active-record-models In essence, if you look in your

i18n Routing To Mounted Engine - Ignoring locale

送分小仙女□ 提交于 2019-11-27 18:23:57
问题 I have an application (my_test_app) with working i18n support built. Currently, there are two language files available, FR & EN, and if I toggle back and forth between them, everything works as I expect to see it for non-engine functions such as the User index/show/edit/delete (ISED) options. Within my_test_app I have a Rails Engine mounted (my_engine) which has a controller & model set (engine_job). So, a workable URL should be http://0.0.0.0:3000/fr/my_engine/engine_job No matter what

ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc 2.4.2+) instead

送分小仙女□ 提交于 2019-11-27 18:08:22
Seems the last post for this problem was closed for one reason or another so I'll try my luck... I'm trying to run a simple "rake db:migrate" command. When I do, I get the error in the title. Yes, the solution "appears" obvious but it's not because I don't my Rakefile does not contain any references to 'rake/rdoctask'. It seems to be coming from documentation.rake but when I try to change that file as recommended by the error, I get a different error. I have found a couple of posts declaring this to be a known issue but nothing I've found indicates how to fix or work around this. Does anyone

How to create a catch-all route in Ruby on Rails?

為{幸葍}努か 提交于 2019-11-27 18:02:59
问题 I want to have all requests that satisfy a certain constraint to go to a specific controller. So I need a catch-all route. How do I specify that in Rails? Is it something like this? match '*', to: 'subdomain_controller#show', constraints: {subdomain: /.+\.users/} Will that really catch all possible routes? It's important that none slip through even if there are many nested directories. Using Ruby on Rails 3.2, but ready to upgrade to 4.0. UPDATE : '*path' seems to work. However, the issue I'm

Difference between Render and Render Partial and Yield

江枫思渺然 提交于 2019-11-27 17:49:08
I have read it from the Rails guides, Have looked at Micheal Hartel book and now reading it from Rails View book but still I get confused :( There is a _footer.html.erb file so it is a "partial" and in the code it has written: <%=render 'layouts/footer' %> so my understanding is that when it sees this, goes and insert the HTML for footer file in here. Ok... Now a few pages later it is saying: <%= render partial: 'activitiy_items/recent' %> so WHY this time we have the word "partial" in here but we didn't have it in the previous one? And there somewhere else I see <%= yield :sidebar %> So this

categories and sub-categories model rails

こ雲淡風輕ζ 提交于 2019-11-27 17:28:13
Without using any gems how do I do this in rails? Main Category Sub Category Sub Category Sub Category Main Category Sub Category Sub Category Sub Category Main Category Sub Category Sub Category Sub Category I have a table that consists of | id | level1 | level2 | Level 1 being the main category and Level 2 being the subcategory I would like it displayed in the view like above. After looking around on the internet everyone seems to recommend using acts-like-a-tree gem, but i want to avoid using them as I'm fairly new to rails and I would like to understand how to do things rather than turn to

Server is already running in Rails

橙三吉。 提交于 2019-11-27 16:45:48
When I am starting rails server using rails s command it is showing A server is already running. Check C:/Sites/folder/Pids/Server.pids When I open the file it is outputting a 4 digit number only so how could I resolve this issue ? FYI No other instance of Rails cmd is running this time. Checked Task manager but only cmd.exe is showing no else process is running. (using Windows). rainkinz Remove the file: C:/Sites/folder/Pids/Server.pids Taimoor Changaiz Old Solution: rails s -p 4000 -P tmp/pids/server2.pid Also you can find this post for more options Rails Update to 3.2.11 breaks running

Erase records every 60 days

£可爱£侵袭症+ 提交于 2019-11-27 16:39:55
问题 I need to erase records in my offers models if the record has more that 60 days from the created_at date. I only found information about how to populate my model with a rake task, but I couldn't find information about how to make a rake task to delete records. So I just wonder if I have to do this with a task or if rails has something else to do this. 回答1: Create a file for the task: # lib/tasks/delete_old_records.rake namespace :delete do desc 'Delete records older than 60 days' task :old

Ruby on Rails - Make Slim the Default Template

主宰稳场 提交于 2019-11-27 15:45:46
问题 I am working on a Ruby on Rails project and am needing to customize default views provided by Gems. The requirement is to use Slim for template. I understand that ERB is the default template engine for Rails. As per my observation, the priority is for ERB and if not it will use Slim/Haml views. I am interested in knowing if it is possible to set Slim as the default instead of the ERB? How can this be achieved so that when I create a local version of a template in Slim it will override the

Rails 3: Get list of routes in namespace programmatically

浪子不回头ぞ 提交于 2019-11-27 14:59:22
问题 Question How can I get a list of all the routes in my Admin namespace so that I can use it in one of my tests? Rationale I frequently make the mistake of inheriting from ApplicationController instead of AdminController when creating new controllers in my Admin namespace. So, I want to write a test that visits all the routes in my Admin namespace and verifies that each one requires a logged in user. 回答1: test_routes = [] Rails.application.routes.routes.each do |route| route = route.path.spec