ruby-on-rails-3.1

build method on ruby on rails

自古美人都是妖i 提交于 2019-11-28 07:13:31
New to rails and I'm following the Depot project found in the Agile web development with rails 3.1. Everything was fine until I got lost when the book used the "build" method. @cart = current_cart product = Product.find(params[:product_id]) @line_item = @cart.line_items.build(product: product) My google searches led me to understand that the .build method is just a cleaner way to create a row in the table (with association between tables). But on the code above, I was expecting the code would look like something like this: @line_item = @cart.line_items.build(product_id => params[:product_id])

Rails 3.2 has_many through form submission

筅森魡賤 提交于 2019-11-28 07:11:25
问题 I have a has_many :through form where I can't get an extra attribute to post to the database. I'm fouling up the parameter name somewhere. I can get the foreign keys to post but I have another attribute that I'm trying to track in the join table. Keep in mind this is a 100% ajax based form. Here's what I know Edit: After researching similar issues, I understand I'm supposed to build the form attributes, but the code I've found doesn't work for some reason. Here are some resources. http:/

How do I associate a CoffeeScript file with a view?

泪湿孤枕 提交于 2019-11-28 06:56:19
Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline By default all coffeescript is compiled into a single application.js file, this is a good thing. Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc... Many of these scripts will be specific to a controller or action, I am trying to grok the 'conventional' way to handle this, since everything is wrapped

Re-source .bashrc when restarting unicorn?

荒凉一梦 提交于 2019-11-28 06:25:36
问题 I have some ENV variables that are sourced for the deploy user. (Similar to what Heroku recommends, but without using Heroku.) My rails app depends on these for certain functions, for example, in application.rb: config.action_mailer.default_url_options = { host: ENV['MY_HOST'] } This is necessary because we have several staging hosts. Each host has MY_HOST defined to its correct hostname in .bashrc like so: export MY_HOST="staging3.example.com" This allows us to only use one rails staging

Rails: How to disable asterisk on form's required fields?

孤街醉人 提交于 2019-11-28 05:44:13
When I add the 'Required' attribute to html input fields, Rails pre-pends an asterisk (*) before the label. Does anyone know how to prevent this? For some reason Rails transforms this: <%= f.input :Company, :input_html => {:value => "", :id => "company_name"}, :label => "company name" %> into this: <div class="input string required"> <label for="company_name" class="string required"> <abbr title="required">*</abbr> company name</label> <input type="text" value="" size="50" required="required" name="lead[Company]" id="company_name" class="string required"> </div> I don't like that it wraps

Rails 3.1 Load css in particular order

大憨熊 提交于 2019-11-28 05:22:06
I see that in development environment in rails 3.1 the css are loaded in alphabetic order and not in the order I want. I want a particular css file to be at the end so it over-writes any styles given to the class before. How can we achieve that? It is better to specify the order of each and every files manually: /* * This is a manifest file that'll automatically include all the stylesheets available in this directory * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at * the top of the compiled file, but it's generally better to create a new

How do I use Controller specific stylesheets in Rails 3.2.1?

狂风中的少年 提交于 2019-11-28 05:01:23
Using Rails 3.2.1 I created a simple controller called Home using the command: rails g controller Home index And it created a new controller and view for me: Notice how there are two stylesheets, one "Application" and one "Home". I can't find any documentation to support this assumption but I'm guessing you put styles that will only be applied to the "Home" views, in the Home.css.scss file, correct? So as a test, I added in some global styles to Application.css.scss.erb and ran the application. The styles applied as expected. Next, I added in some rules to the Home.css.scss file and I visited

Devise redirect after confirmation

落花浮王杯 提交于 2019-11-28 04:20:20
How can I create an after confirmation redirect in devise? Before I added the confirmation module the custom after_sign_up_path worked fine for the first time login/signup but now when I click the confirmation link in the email it redirects to the path i set for the after login path (user profile). My goal here is to create a form wizard and "getting started" page to collect additional information. The obvious caveat being that this redirect will only happen 1 time, upon confirmation. I have tried some other solutions that have been posted on stack but none of them seem to work any longer..

Error while loading shared libraries: 'libpcre.so.0: cannot open shared object file: No such file or directory'

一个人想着一个人 提交于 2019-11-28 04:10:30
I just installed Passenger 3.0.11 and nginx and got this error: Starting nginx: /opt/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory The message means what it says. The nginx executable was compiled to expect the PCRE (Perl-compatible Regular Expression) shared library to be available somewhere on LD_LIBRARY_PATH or specified in /etc/ld.so.conf or whatever equivalent library-locating mechanisms apply to your operating system, and it cannot find the library. You will need to install PCRE - or configure your

find(:first) and find(:all) are deprecated

ぃ、小莉子 提交于 2019-11-28 03:54:01
问题 I am using RubyMine with rails 3.2.12 and I am getting following deprecated warning in my IDE. Any Idea How can I solve this deprecated warning? find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2. 回答1: I changed my answer after @keithepley comment #Post.find(:all, :conditions => { :approved => true }) Post.where(:approved => true).all #Post.find(:first, :conditions => { :approved => true }) Post.where(:approved => true).first