ruby-on-rails-3.2

Difference between Render and Render Partial and Yield

烈酒焚心 提交于 2019-11-27 04:13:19
问题 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

How to get a Date from date_select or select_date in Rails?

删除回忆录丶 提交于 2019-11-27 03:57:46
Using select_date gives me back a params[:my_date] with year , month and day attributes. How do get a Date object easily? I'm hoping for something like params[:my_date].to_date . I'm happy to use date_select instead as well. Using date_select gives you 3 separate key/value pairs for the day, month, and year respectively. So you can pass them into Date.new as parameters to create a new Date object. An example date_select returned params for an Event model: "event"=> {"name"=>"Birthday", "date(1i)"=>"2012", "date(2i)"=>"11", "date(3i)"=>"28"}, Then to create the new Date object: event = params[

Mongoid Group By or MongoDb group by in rails

守給你的承諾、 提交于 2019-11-27 03:40:02
问题 I have a mongo table that has statistical data like the following.... course_id status which is a string, played or completed and timestamp information using Mongoid's Timestamping feature so my class is as follows... class Statistic include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia field :course_id, type: Integer field :status, type: String # currently this is either play or complete I want to get a daily count of total # of plays for a course. So for example...

How can I iterate through a MySQL result set?

一曲冷凌霜 提交于 2019-11-27 03:15:20
问题 Here is the code I'm using: # Run the query against the database defined in .yml file. # This is a Mysql::result object - http://www.tmtm.org/en/mysql/ruby/ @results = ActiveRecord::Base.connection.execute(@sql_query) In my View, here's what I do to see the values: <pre><%= debug @results %></pre> Outputs: #<Mysql2::Result:0x007f31849a1fc0> <% @results.each do |val| %> <%= val %> <% end %> Outputs: ["asdfasdf", 23, "qwefqwef"] ["sdfgdsf", 23, "asdfasdfasdf"] So imagine I query something like

Status of Rails' link_to_function deprecation?

China☆狼群 提交于 2019-11-27 02:37:19
问题 What is the status of the link_to_function Javascript helper in Rails? I read, including in this stackoverflow question, that it was deprecated in Rails 3.0, then undeprecated, then deprecated again in 3.2.4. Is it something I can depend on and teach students? I just read the release notes (from a search) for Rails 3.2.8: Reverted the deprecation of button_to_function and link_to_function helpers. Rafael Mendonça França Where does this stand now? 回答1: link_to_function is NOT deprecated in 3-2

Use rvmrc or ruby-version file to set a project gemset with RVM?

本秂侑毒 提交于 2019-11-27 02:29:29
I use RVM, the Ruby Version Manager to specify a Ruby version and a set of gems for each of my Rails projects. I have a .rvmrc file to automatically select a Ruby version and gemset whenever I cd into a project directory. After installing RVM 1.19.0, I get a message You are using .rvmrc , it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to .ruby-version using rvm rvmrc to [.]ruby-version or ignore this warnings with rvm rvmrc warning ignore /Users/userName/code/railsapps/rails-prelaunch-signup/.rvmrc , .rvmrc will continue to be the default

Rails 3.2 Modal popup on show action

蓝咒 提交于 2019-11-27 02:24:09
问题 None of the questions on this forum seem to address my specific need. Basically, I have a "Details" button. I want it that when it clicks, a modal dialog shows up with information drawn from the show.html.erb of the model. I have a book.rb model. In the index page I have: <div class="detail_button"><%= link_to "Details", book %></div> Clicking this button normally would take me to the book/id page, using the show action. But I don't want it to leave the page, rather I want a modal popup which

Rails 3.2 undefined method `key?' for nil:NilClass

时光总嘲笑我的痴心妄想 提交于 2019-11-27 02:11:25
问题 For some reason I started to get this error after switching to Rails 3.2. I guess it has something to do with acl9 plugin, which I tried reinstalling, but nothing changed. I moved the plugins to lib/plugins and added initializer to config/initializers but again, same error. I looked for solution at acl9 repo on Github, but could not find anything there. Maybe it is not acl9 after all. I have paperclip, acl9, authlogic installed. NoMethodError (undefined method `key?' for nil:NilClass):

what is the difference between link_to, redirect_to, and render?

…衆ロ難τιáo~ 提交于 2019-11-27 02:08:55
问题 I am confused about the main difference(s) among link_to , redirect_to and render in Rails. anyone can please explain. 回答1: link_to is used in your view, and generates html code for a link <%= link_to "Google", "http://google.com" %> This will generate in your view the following html <a href="http://google.com">Google</a> redirect_to and render are used in your controller to reply to a request. redirect_to will simply redirect the request to a new URL, if in your controller you add redirect

Reserved names with ActiveRecord models

非 Y 不嫁゛ 提交于 2019-11-26 22:55:45
问题 I take naming pretty seriously, so I think pretty hard about good names for my ActiveRecord models. However, I frequently come up with a name and it has some conflict with a reserved name, either in the database or Ruby or Rails. Model or field names like set or group . Sometimes the issue isn't immediately apparent either. Is there a list somewhere of names we can't use in our model names and a list for field names? 回答1: Here's a couple of resources to get you started: Rails reserved words.