ruby-on-rails-3.1

Rails routes with optional scope “:locale”

橙三吉。 提交于 2019-11-27 23:41:12
I'm working on a Rails 3.1 app and I'd like to set specific routes for the different languages the app is going to support. /es/countries /de/countries … For the default language ('en'), I don't want the locale to be displayed in the url. /countries Here is the route definition I've set. scope "(:locale)", :locale => /es|de/ do resources :countries end It works great, until I try to use a path helper with 'en' as the locale. In the console : app.countries_path(:locale => 'fr') => "/fr/countries" app.countries_path(:locale => 'en') => "/countries?locale=en" I don't want the "?locale=en". Is

Passing parameters from view to controller

橙三吉。 提交于 2019-11-27 22:19:01
I got a bit of a newbie question. I'm trying to pass a variable from my view to my controller. Is there anyway my method in my controller can receive variables from my view? Post view: show.html.erb: .... <%=link_to "Add relationship", :method => :add_relationship(@rela) %> Controller: post.controller.rb: def add_relationship(rela) @post = Post.find(params[:id]) if current_user.id == @post.user_id @post.rel_current_id = rela.id @post.save redirect_to relationships_url else redirect_to posts_url, :notice => "FY!" end end Thanks in advance :) You can add information to the params hash right

Rails 3.1 Errno::EACCES Permission Denied

这一生的挚爱 提交于 2019-11-27 21:15:00
问题 Rails 3.1 Passenger on Apache Development environment When I go to access the index (i.e. GET) for a route I get: Errno::EACCES in Crb_agendas#index Showing /var/www/crbagenda/app/views/layouts/application.html.erb where line #5 raised: Permission denied - /var/www/crbagenda/tmp/cache/assets/E2C Extracted source (around line #5): 2: <html> 3: <head> 4: <title>CrbAgendas</title> 5: <%= stylesheet_link_tag "application" %> 6: <%= javascript_include_tag "application" %> 7: <%= csrf_meta_tags %>

Broken precompiled assets in Rails 3.1 when deploying to a sub-URI

感情迁移 提交于 2019-11-27 21:08:54
问题 I'm in the process of updating a Rails 3 app to use Rails 3.1 and as part of that, am making use of the new asset pipeline. So far, I've got everything working apart from one rather annoying problem I can't solve. The application and all its assets works fine in development, but in production it is deployed to a sub-URI using Passenger ( http://the-host/sub-uri/ ). The problem with this is that the assets are pre-compiled during deployment and one of my CSS (well, it's a .css.scss file) files

Does form_tag work with Simple_form?

半世苍凉 提交于 2019-11-27 20:01:31
问题 I have a form that is using form_tag and not sure how to use it with the simple_form gem. This is how my form looks: <%= form_tag create_multiple_prices_path, :method => :post do %> <% @prices.each_with_index do |price, index| %> <%= fields_for "prices[#{index}]", price do |up| %> <%= render "fields", :f => up %> <% end %> <% end %> <%= submit_tag "Done" %> <% end %> Can it be done? How would a form_tag change to use simple_form correctly? What about when using it with fields_for ? A Newbie

skip certain validation method in Model

孤街醉人 提交于 2019-11-27 19:40:37
I am using Rails v2.3 If I have a model : class car < ActiveRecord::Base validate :method_1, :method_2, :method_3 ... # custom validation methods def method_1 ... end def method_2 ... end def method_3 ... end end As you see above, I have 3 custom validation methods , and I use them for model validation. If I have another method in this model class which save an new instance of the model like following: # "flag" here is NOT a DB based attribute def save_special_car flag new_car=Car.new(...) new_car.save #how to skip validation method_2 if flag==true end I would like to skip the validation of

Deploy Rails Application on EC2

若如初见. 提交于 2019-11-27 19:32:32
For the past week, I've been playing with the Rubber gem and can't seem to get it to work. I've decided it would be easier just to manually set up my EC2 instance. The problem is that I don't know how. Google hasn't been much help for a newb either. Any suggestions? It really is appreciated. Sure. Create a AWS account. Decided what region you want to be in. Lots of things go into this decision, but worry about it later and just do a cheap one like Oregon or East. Make sure you are in the correct region at the top left. Then click launch server. At this point you have to pick a AMI. An AMI is

Rails 3.1: Better way to expose an engine's helper within the client app

做~自己de王妃 提交于 2019-11-27 19:22:42
I have found a few articles addressing the issue of helpers within an engine not being accessible to the consuming (parent) application. To make sure we are all on the same page, let's say we have this: module MyEngine module ImportantHelper def some_important_helper ...do something important... end end end If you look at the rails engine documentation in the "Isolated engine's helpers" (L293), it says: # Sometimes you may want to isolate engine, but use helpers that are defined for it. # If you want to share just a few specific helpers you can add them to application's # helpers in

How to set up factory in FactoryGirl with has_many association

▼魔方 西西 提交于 2019-11-27 19:14:05
问题 Can someone tell me if I'm just going about the setup the wrong way? I have the following models that have has_many.through associations: class Listing < ActiveRecord::Base attr_accessible ... has_many :listing_features has_many :features, :through => :listing_features validates_presence_of ... ... end class Feature < ActiveRecord::Base attr_accessible ... validates_presence_of ... validates_uniqueness_of ... has_many :listing_features has_many :listings, :through => :listing_features end

How to increase Heroku log drain verbosity to include all Rails app details?

一世执手 提交于 2019-11-27 18:38:16
问题 Presently I'm running a Rails 3.1.x app atop Heroku Celadon Cedar and it seems that log verbosity is very much lacking. I have set the log level to DEBUG a la heroku config:add LOG_LEVEL=DEBUG --app app_name , which matched up to their recommendation, however beyond that I cannot seem to pull in the log/* file contents. Changing from Thin to Unicorn did increase verbosity slightly, but only in web worker requests. I still cannot pull down the db requests and so forth. What is the best way to