[Rails] I wrote an Upgrade to Rails 4 ebook
Hello all! I just published a leanpub book on how to upgrade your Rails 3 application to Rails 4. It covers all new features introduced in Rails 4 and contains the deprecated features as well. You can follow along with an included upgrade checklist to see if you upgraded all breaking changes from Rails 3 to Rails 4. You can get it over here: http://www.leanpub.com/upgradetorails4. Feedback and suggestions are very welcome. Thanks! Cheers, Philip -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/b_KHu4yAau4J. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] 'rails c' command throws back error
Hi, I am new to ruby and rails. I have been working through a few tutorials etc trying to get up to speed. However I have run into one issue I'm unsure how to go about solving. I am using RVM to manage my ruby verions. By default I have 1.8.7 installed on my system(Ubuntu man, but I am on Linux Mint Maya). With my latest project however I am using 1.9.3(with rails 3.2.11). Everything works great and I very happy, but when I try run rails c or rails console I get the following error... /home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError) from /home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `top (required)' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `require' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `top (required)' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `require' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `top (required)' from script/rails:6:in `require' from script/rails:6:in `main' So as a result I am unable to use the console at all on this project. If anybody had any clue on how to solve this I would be most grateful! ps when I run rvm use 1.9.3 it returns... Using /home/phil/.rvm/gems/ruby-1.9.3-p392 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Qv8IPD8beakJ. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] 'rails c' command throws back error
On Ubuntu you need libreadline6 and libreadline6-dev, though I don't know whether that is the same on mint. You might need to remove and re-install ruby in rvm after installing libreadline so that it re-compiles with the right options. The full list of stuff I install before installing rvm is sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core \ zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev autoconf libc6-dev ncurses-dev automake \ libtool By the way, when you get an error you don't understand often the best route is to put the error message into google. I think that would have taken you to a solution very quickly. Colin On 1 April 2013 14:21, Phil phil...@gmail.com wrote: Hi, I am new to ruby and rails. I have been working through a few tutorials etc trying to get up to speed. However I have run into one issue I'm unsure how to go about solving. I am using RVM to manage my ruby verions. By default I have 1.8.7 installed on my system(Ubuntu man, but I am on Linux Mint Maya). With my latest project however I am using 1.9.3(with rails 3.2.11). Everything works great and I very happy, but when I try run rails c or rails console I get the following error... /home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `require': cannot load such file -- readline (LoadError) from /home/phil/.rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/irb/completion.rb:9:in `top (required)' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `require' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands/console.rb:3:in `top (required)' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `require' from /home/phil/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.11/lib/rails/commands.rb:38:in `top (required)' from script/rails:6:in `require' from script/rails:6:in `main' So as a result I am unable to use the console at all on this project. If anybody had any clue on how to solve this I would be most grateful! ps when I run rvm use 1.9.3 it returns... Using /home/phil/.rvm/gems/ruby-1.9.3-p392 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Qv8IPD8beakJ. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] respond_with conditions
Hello All, I want to pass conditions in respond_with like this: user = User.where(updated_at = :start_date AND updated_at = :end_date, {:start_date = some_date, :end_date = Time.now}) respond_with(user, :include = :sub_users) I need to pass the same parameters in case of sub users. How can I achieve this? Thanks, Avi -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/xiicnqcIABsJ. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: How to set exception in client side validation gem
thanks for advice, but that doesn't work вторник, 2 апреля 2013 г., 1:07:14 UTC+4 пользователь Barry написал: As you may know, this gem initializer file has code, which you need to uncomment to show validation error inline to every form field: # Uncomment the following block if you want each input field to have the validation messages attached. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| unless html_tag =~ /^label/ %{div class=field_with_errors#{html_tag}label for=#{instance.send(:tag_id)} class=message#{instance.error_message.first}/label/div}.html_safe else %{div class=field_with_errors#{html_tag}/div}.html_safe end end I uncommented this code, but for one special model I want to display errors as usual. I tried to refactor default code ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if #{instance.send(:tag_id)}!=answer_user_answer #that's label for this model unless html_tag =~ /^label/ %{div class=field_with_errors#{html_tag}label for=#{instance.send(:tag_id)} class=message#{instance.error_message.first}/label/div}.html_safe else %{div class=field_with_errors#{html_tag}/div}.html_safe end end end but that doesn't work. Thanks in advance for help -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/KYZqDTrc3goJ. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: Revisiting deployment on a dedicated server
Depending on your app feature, The best choice is varying. For rails server, unicorn and puma are latest one. 2013년 4월 2일 화요일 오전 5시 10분 1초 UTC+9, Phil 님의 말: I'm in the midst of a few new Rails deployments as well as being tasked to revise an existing older deployment to help improve performance. So, I'm wondering what sort of setup is preferable these days for a dedicated server? The basics I'm aiming to start with are the latest CentOS/RHEL, PostgreSQL, Ruby 2.x, Rails and Apache. Is Passenger still the way to go these days? Just curious what others are using these days. BTW- I've looked into and have used third party hosting, like Heroku, but for these particular projects we have to keep the apps and data on physical servers managed by the customers for legal reasons. Thanks! Phil -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/r6vqwJ8UV3IJ. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] respond_with conditions
I want to pass conditions in respond_with like this: user = User.where(updated_at = :start_date AND updated_at = :end_date, {:start_date = some_date, :end_date = Time.now}) respond_with(user, :include = :sub_users) I need to pass the same parameters in case of sub users. How can I achieve this? Thanks, Avi Why would you do this? The respond_with method is used to initialize a responder, which will only set the path to go to. If u need an association, you must do this on your where call. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br. Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] respond_with conditions
I want json data passing date parameter ... As users has_many sub_users I want those sub_users data also with same condition as users. Is it possible to achieve that ? - Reply message - From: Paulo Henrique Lopes Ribeiro plribeiro3...@gmail.com To: rubyonrails-talk@googlegroups.com Subject: [Rails] respond_with conditions Date: Tue, Apr 2, 2013 6:56 pm I want to pass conditions in respond_with like this: user = User.where(updated_at = :start_date AND updated_at = :end_date, {:start_date = some_date, :end_date = Time.now}) respond_with(user, :include = :sub_users) I need to pass the same parameters in case of sub users. How can I achieve this? Thanks, Avi Why would you do this? The respond_with method is used to initialize a responder, which will only set the path to go to. If u need an association, you must do this on your where call. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br. Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] respond_with conditions
Sure it is possible. The only thing is, the right place isn't inside respond_with. =p 2013/4/2 aavinash.beh...@gmail.com aavinash.beh...@gmail.com I want json data passing date parameter ... As users has_many sub_users I want those sub_users data also with same condition as users. Is it possible to achieve that ? - Reply message - From: Paulo Henrique Lopes Ribeiro plribeiro3...@gmail.com To: rubyonrails-talk@googlegroups.com Subject: [Rails] respond_with conditions Date: Tue, Apr 2, 2013 6:56 pm I want to pass conditions in respond_with like this: user = User.where(updated_at = :start_date AND updated_at = :end_date, {:start_date = some_date, :end_date = Time.now}) respond_with(user, :include = :sub_users) I need to pass the same parameters in case of sub users. How can I achieve this? Thanks, Avi Why would you do this? The respond_with method is used to initialize a responder, which will only set the path to go to. If u need an association, you must do this on your where call. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br. Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br. Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] gmaps4rails: undefined method `model_name' for NilClass:Class
Hi All, just in a spot of bother with this gem, I am trying to create a new location and get the above msg. here is my controller: class LocationsController ApplicationController # GET /locations # GET /locations.json def index @locations = Location.all @json = Location.all.to_gmaps4rails end respond_to do |format| format.html # index.html.erb format.json { render json: @locations } end end # GET /locations/1 # GET /locations/1.json def show @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| format.html # show.html.erb format.json { render json: @location } end end # GET /locations/new # GET /locations/new.json def new @location = Location.new @json = Location.all.to_gmaps4rails respond_to do |format| format.html # new.html.erb format.json { render json: @location } end end # GET /locations/1/edit def edit @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails end # POST /locations # POST /locations.json def create @location = Location.new(params[:location]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.save format.html { redirect_to @location, notice: 'Location was successfully created.' } format.json { render json: @location, status: :created, location: @location } else format.html { render action: new } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # PUT /locations/1 # PUT /locations/1.json def update @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.update_attributes(params[:location]) format.html { redirect_to @location, notice: 'Location was successfully updated.' } format.json { head :no_content } else format.html { render action: edit } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # DELETE /locations/1 # DELETE /locations/1.json def destroy @location = Location.find(params[:id]) @location.destroy @json = Location.all.to_gmaps4rails respond_to do |format| format.html { redirect_to locations_url } format.json { head :no_content } end end and the _form I use to create the new location: %= form_for(@location) do |f| % % if @location.errors.any? % div id=error_explanation h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 ul % @location.errors.full_messages.each do |msg| % li%= msg %/li % end % /ul /div % end % div class=field %= f.label :id %br / %= f.number_field :id % /div div class=field %= f.label :name %br / %= f.text_field :name % /div div class=field %= f.label :coordinates %br / %= f.text_field :coordinates % /div div class=field %= f.label :course_id %br / %= f.number_field :course_id % /div div class=field %= f.label :college_id %br / %= f.number_field :college_id % /div div class=actions %= f.submit % /div % end % This is the error msg in full: NoMethodError in Locations#new Showing *C:/Postgrads0204/app/views/locations/_form.html.erb* where line *#1 * raised: undefined method `model_name' for NilClass:Class Extracted source (around line *#1*): 1: %= form_for(@location) do |f| % 2: % if @location.errors.any? % 3: div id=error_explanation 4: h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 Trace of template inclusion: app/views/locations/new.html.erb Rails.root: C:/Postgrads0204 Application Trace http://localhost:3000/locations/new# | Framework Tracehttp://localhost:3000/locations/new# | Full Trace http://localhost:3000/locations/new# app/views/locations/_form.html.erb:1:in `_app_views_locations__form_html_erb___82209480_46213008' app/views/locations/new.html.erb:3:in `_app_views_locations_new_html_erb___810294894_46206828' Any Ideas where am I going wrong? Cheers J -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/aCsSvcAzghAJ. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] gmaps4rails: undefined method `model_name' for NilClass:Class
On 2 April 2013 15:34, Jax javier_rossetti1...@hotmail.com wrote: NoMethodError in Locations#new Showing C:/Postgrads0204/app/views/locations/_form.html.erb where line #1 raised: undefined method `model_name' for NilClass:Class Extracted source (around line #1): 1: %= form_for(@location) do |f| % The problem is nothing to do with the gem. @location is nil. Are you passing the value across when you render the form? It seems to be the only bit of code that you have not shown us. See http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials for how to pass data to the form. Also have a look at the Rails Guide on debugging with will show you techniques that you can use to debug your code. Colin -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: Why Did Capybara Move Specs into spec/features?
Thanks for the advice on the upcoming RSpec expect syntax. On Sunday, March 31, 2013 2:16:50 AM UTC-7, Gjaldon wrote: Here's a post by Jose Valim on the reasoning behind the change: http://blog.plataformatec.com.br/2012/06/improving-the-integration-between-capybara-and-rspec/ As a quick summary, Capybara is an acceptance test framework and as such, tests should be written from a browser or user's perspective. With the rspec-rails gem, tests found in spec/requests directory have access to methods that expose lower-level details like requests and responses(methods like get, put, post.) So if Capybara tests are also found in that same spec/requests directory, you are able to use both the Capybara DSL and the free methods that are meant for integration tests which causes a conflict and leads to some developers using a mix of both. This leads to ugly test suites. The solution they came up with is to create a separate directory meant for use with Capybara DSL, which is spec/features and another directory (spec/api) meant for use with the Rails provided integration test tools. Michael Hartl will be releasing a newer version of his tutorial sometime in the future which will provide more up-to-date material. You might also want to look at RSpec's 'expect' syntax for its assertions. They plan on deprecating the 'should' syntax possibly as early as RSpec 3.0. On Sunday, March 31, 2013 1:57:30 PM UTC+8, Peter wrote: Hello Everyone, I am new to Ruby on Rails. I just finished Michael Hartl's *Ruby on Rails Tutorial*http://ruby.railstutorial.org/ruby-on-rails-tutorial-book and I just started on *Agile Web Development with Rails, Fourth Edition* by Sam Rubyhttp://pragprog.com/book/rails4/agile-web-development-with-rails. In trying to build confidence and proficiency, I started building small apps and decided, as I had learned from Michael Hartl, to use capybarahttps://github.com/jnicklas/capybaraand rspec https://github.com/rspec/rspec. But when I tried it nothing was working. It turns out, this was the reason: If you are using Rails, put your Capybara specs in spec/features. And in order to use the tests I had created in spec/requests, I have to do this: If you are not using Rails, tag all the example groups in which you want to use Capybara with :type = :feature. Can anyone explain the reasoning behind this? I'm sure there is a good reason for this that my newbie self does not comprehend yet. Thank you in advance. p -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kybOhYfoTbUJ. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: gmaps4rails: undefined method `model_name' for NilClass:Class
Hi Colin, Thank you for your comment, I was actually missing a end tag to close off the class in the controller! Cheers anyway J On Tuesday, April 2, 2013 3:34:11 PM UTC+1, Jax wrote: Hi All, just in a spot of bother with this gem, I am trying to create a new location and get the above msg. here is my controller: class LocationsController ApplicationController # GET /locations # GET /locations.json def index @locations = Location.all @json = Location.all.to_gmaps4rails end respond_to do |format| format.html # index.html.erb format.json { render json: @locations } end end # GET /locations/1 # GET /locations/1.json def show @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| format.html # show.html.erb format.json { render json: @location } end end # GET /locations/new # GET /locations/new.json def new @location = Location.new @json = Location.all.to_gmaps4rails respond_to do |format| format.html # new.html.erb format.json { render json: @location } end end # GET /locations/1/edit def edit @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails end # POST /locations # POST /locations.json def create @location = Location.new(params[:location]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.save format.html { redirect_to @location, notice: 'Location was successfully created.' } format.json { render json: @location, status: :created, location: @location } else format.html { render action: new } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # PUT /locations/1 # PUT /locations/1.json def update @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.update_attributes(params[:location]) format.html { redirect_to @location, notice: 'Location was successfully updated.' } format.json { head :no_content } else format.html { render action: edit } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # DELETE /locations/1 # DELETE /locations/1.json def destroy @location = Location.find(params[:id]) @location.destroy @json = Location.all.to_gmaps4rails respond_to do |format| format.html { redirect_to locations_url } format.json { head :no_content } end end and the _form I use to create the new location: %= form_for(@location) do |f| % % if @location.errors.any? % div id=error_explanation h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 ul % @location.errors.full_messages.each do |msg| % li%= msg %/li % end % /ul /div % end % div class=field %= f.label :id %br / %= f.number_field :id % /div div class=field %= f.label :name %br / %= f.text_field :name % /div div class=field %= f.label :coordinates %br / %= f.text_field :coordinates % /div div class=field %= f.label :course_id %br / %= f.number_field :course_id % /div div class=field %= f.label :college_id %br / %= f.number_field :college_id % /div div class=actions %= f.submit % /div % end % This is the error msg in full: NoMethodError in Locations#new Showing *C:/Postgrads0204/app/views/locations/_form.html.erb* where line * #1* raised: undefined method `model_name' for NilClass:Class Extracted source (around line *#1*): 1: %= form_for(@location) do |f| % 2: % if @location.errors.any? % 3: div id=error_explanation 4: h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 Trace of template inclusion: app/views/locations/new.html.erb Rails.root: C:/Postgrads0204 Application Trace http://localhost:3000/locations/new# | Framework Tracehttp://localhost:3000/locations/new# | Full Trace http://localhost:3000/locations/new# app/views/locations/_form.html.erb:1:in `_app_views_locations__form_html_erb___82209480_46213008' app/views/locations/new.html.erb:3:in `_app_views_locations_new_html_erb___810294894_46206828' Any Ideas where am I going wrong? Cheers J -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit
Re: [Rails] Re: gmaps4rails: undefined method `model_name' for NilClass:Class
On 2 April 2013 17:06, Jax javier_rossetti1...@hotmail.com wrote: Hi Colin, Thank you for your comment, I was actually missing a end tag to close off the class in the controller! A missing end tag in the controller code gave you the error undefined method `model_name' for NilClass:Class? That is unusual. I would have expected to get a syntax error about the missing end when the class was loaded. Colin Cheers anyway J On Tuesday, April 2, 2013 3:34:11 PM UTC+1, Jax wrote: Hi All, just in a spot of bother with this gem, I am trying to create a new location and get the above msg. here is my controller: class LocationsController ApplicationController # GET /locations # GET /locations.json def index @locations = Location.all @json = Location.all.to_gmaps4rails end respond_to do |format| format.html # index.html.erb format.json { render json: @locations } end end # GET /locations/1 # GET /locations/1.json def show @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| format.html # show.html.erb format.json { render json: @location } end end # GET /locations/new # GET /locations/new.json def new @location = Location.new @json = Location.all.to_gmaps4rails respond_to do |format| format.html # new.html.erb format.json { render json: @location } end end # GET /locations/1/edit def edit @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails end # POST /locations # POST /locations.json def create @location = Location.new(params[:location]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.save format.html { redirect_to @location, notice: 'Location was successfully created.' } format.json { render json: @location, status: :created, location: @location } else format.html { render action: new } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # PUT /locations/1 # PUT /locations/1.json def update @location = Location.find(params[:id]) @json = Location.all.to_gmaps4rails respond_to do |format| if @location.update_attributes(params[:location]) format.html { redirect_to @location, notice: 'Location was successfully updated.' } format.json { head :no_content } else format.html { render action: edit } format.json { render json: @location.errors, status: :unprocessable_entity } end end end # DELETE /locations/1 # DELETE /locations/1.json def destroy @location = Location.find(params[:id]) @location.destroy @json = Location.all.to_gmaps4rails respond_to do |format| format.html { redirect_to locations_url } format.json { head :no_content } end end and the _form I use to create the new location: %= form_for(@location) do |f| % % if @location.errors.any? % div id=error_explanation h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 ul % @location.errors.full_messages.each do |msg| % li%= msg %/li % end % /ul /div % end % div class=field %= f.label :id %br / %= f.number_field :id % /div div class=field %= f.label :name %br / %= f.text_field :name % /div div class=field %= f.label :coordinates %br / %= f.text_field :coordinates % /div div class=field %= f.label :course_id %br / %= f.number_field :course_id % /div div class=field %= f.label :college_id %br / %= f.number_field :college_id % /div div class=actions %= f.submit % /div % end % This is the error msg in full: NoMethodError in Locations#new Showing C:/Postgrads0204/app/views/locations/_form.html.erb where line #1 raised: undefined method `model_name' for NilClass:Class Extracted source (around line #1): 1: %= form_for(@location) do |f| % 2: % if @location.errors.any? % 3: div id=error_explanation 4: h2%= pluralize(@location.errors.count, error) % prohibited this location from being saved:/h2 Trace of template inclusion: app/views/locations/new.html.erb Rails.root: C:/Postgrads0204 Application Trace | Framework Trace | Full Trace app/views/locations/_form.html.erb:1:in `_app_views_locations__form_html_erb___82209480_46213008' app/views/locations/new.html.erb:3:in `_app_views_locations_new_html_erb___810294894_46206828' Any Ideas where am I going wrong? Cheers J -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to
[Rails] invoking helper method in controller and view breaks the separation of concern?
I came across some posts which postulate that it's undesirable to share helper methods across controller and views because UI code (designed to render HTML) should be separate from controller code (designed for handling requests). That makes sense but there are times, a good example is filtering, when it only makes sense to create a reusable method to query against the params hash from both controller and view. For example, I created some custom filtering and sorting. When a http request is initially made, my controller must be able to query the database for results without user input. # controller layer (query a default without user input) helper_method :sort_column, :sort_direction, :for_selected_month, :for_selected_year def driver_reports_table @drivers = Driver.select(drivers.*, #{sort_column}).joins([:reports, :driving_habits]).by_month(for_selected_month.to_i, for_selected_year.to_i).order(sort_column + + sort_direction).page(params[:page]).per(10) @unit = current_unit respond_to do |format| format.html { render :partial = '/home/reports/ driver_reports_table', :layout = false, :locals = { :drivers = @drivers, :unit = @unit } } format.json { render :json = @drivers} end end private def sort_column if legal_attributes.include? params[:order] params[:order] else drivers.id end end def sort_direction %w[asc desc].include?(params[:direction]) ? params[:direction] : asc end def for_selected_month (params[:date] params[:date][:month]) || Time.now.month end def for_selected_year (params[:date] params[:date][:year]) || Time.now.year end def legal_attributes @columns ||= Driver.column_names + DrivingHabit.column_names end In my view layer, the user will interact with form elements and links to modify the values of the params hash In one situation, I have a form tag where the user will set the date and date and month/year attributes of the params hash: #view = form_tag driver_reports_path, :method = 'get', :id = 'drivers_filter' do %fieldset.filter_tab = select_month(Date.today) = select_year(Date.today, :start_year = 2012, :end_year = Time.now.year) = submit_tag Filter Date = render '/home/reports/driver_reports_table' In another situation, I have links where the user will set the sort and direction attributes of the params hash, depending on which link they click: #partial = hidden_field_tag :sort, params[:sort] = hidden_field_tag :direction, params[:direction] ... %table.sortable %tr = sortable id, :order = drivers.id #helper def sortable(column, query_string={}) title ||= column.titleize query_string[:order] = query_string[:order] || column css_class = 'driver_refresh' css_class (column == sort_column.gsub(driving_habits.,).gsub(drivers.,) ? current #{sort_direction} : ) query_string[:direction] = column == sort_column.gsub(driving_habits.,).gsub(drivers.,) sort_direction == asc ? desc : asc query_string[:page] = nil content_tag :th, link_to(title, driver_reports_path(params.merge(query_string)), {:class = css_class }) end Each of the situations compensate for the other. If the user selects an option from the select tag and thus populates the date attributes, when they click a link, it will merge the date attributes from the form with the link attributes that were selected and thus send them together to the server. Conversely, when the form is submitted, because of the hidden field tags with the current value of the sort and direction attributes stored in them, those attributes will be send with the form attributes. As you can see, my view helper makes use of the sort_column and sort_direction methods to check the current values in the params hash to determine how to render the links. So those methods have importance both in the controller and view layer. So it would make sense to define the methods once and reuse them in both layers. So what is wrong with this technique and how else could it be done so as not to violate the MVC structure and separation of concerns? -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: How to set exception in client side validation gem
Ok guys, finally gem caused several issues, which was hard to debug, so finally I just set up my own jquery validation, and it was no so hard as I imagined. Like this solution, not always gems are suitable, and it was good practice) вторник, 2 апреля 2013 г., 1:07:14 UTC+4 пользователь Barry написал: As you may know, this gem initializer file has code, which you need to uncomment to show validation error inline to every form field: # Uncomment the following block if you want each input field to have the validation messages attached. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| unless html_tag =~ /^label/ %{div class=field_with_errors#{html_tag}label for=#{instance.send(:tag_id)} class=message#{instance.error_message.first}/label/div}.html_safe else %{div class=field_with_errors#{html_tag}/div}.html_safe end end I uncommented this code, but for one special model I want to display errors as usual. I tried to refactor default code ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if #{instance.send(:tag_id)}!=answer_user_answer #that's label for this model unless html_tag =~ /^label/ %{div class=field_with_errors#{html_tag}label for=#{instance.send(:tag_id)} class=message#{instance.error_message.first}/label/div}.html_safe else %{div class=field_with_errors#{html_tag}/div}.html_safe end end end but that doesn't work. Thanks in advance for help -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/vJ3wn4YJdO8J. For more options, visit https://groups.google.com/groups/opt_out.
[Rails] Re: rails source fields_for has an options hash not defined anywhere
I want to know this too. Did you find out? On Wednesday, March 21, 2012 2:12:09 PM UTC-7, John Merlino wrote: Hey all, I looked at source code for fields_for: def fields_for(record_name, record_object = nil, fields_options = {}, block) fields_options, record_object = record_object, nil if record_object.is_a?(Hash) record_object.extractable_options? fields_options[:builder] ||= options[:builder] fields_options[:parent_builder] = self fields_options[:namespace] = fields_options[:parent_builder].options[:namespace] case record_name when String, Symbol if nested_attributes_association?(record_name) return fields_for_with_nested_attributes(record_name, record_object, fields_options, block) end else record_object = record_name.is_a?(Array) ? record_name.last : record_name record_name = ActiveModel::Naming.param_key(record_object) end index = if options.has_key?(:index) [#{options[:index]}] elsif defined?(@auto_index) self.object_name = @object_name.to_s.sub(%r\[\]$/,) [#{@auto_index}] end record_name = #{object_name}#{index}[#{record_name}] @template.fields_for(record_name, record_object, fields_options, block) end Notice this part: options[:builder] this options hash is no where to be defined. In argument list, there's only a fields_options hash. Reason why this matters to me is because I am trying to override this method in my application_helper.rb in order to extend it. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/3Mn0MtAYoIsJ. For more options, visit https://groups.google.com/groups/opt_out.
Re: [Rails] respond_with conditions
If I want to fetch the json data in nested form ? On Tue, Apr 2, 2013 at 7:52 PM, Paulo Henrique Lopes Ribeiro plribeiro3...@gmail.com wrote: Sure it is possible. The only thing is, the right place isn't inside respond_with. =p 2013/4/2 aavinash.beh...@gmail.com aavinash.beh...@gmail.com I want json data passing date parameter ... As users has_many sub_users I want those sub_users data also with same condition as users. Is it possible to achieve that ? - Reply message - From: Paulo Henrique Lopes Ribeiro plribeiro3...@gmail.com To: rubyonrails-talk@googlegroups.com Subject: [Rails] respond_with conditions Date: Tue, Apr 2, 2013 6:56 pm I want to pass conditions in respond_with like this: user = User.where(updated_at = :start_date AND updated_at = :end_date, {:start_date = some_date, :end_date = Time.now}) respond_with(user, :include = :sub_users) I need to pass the same parameters in case of sub users. How can I achieve this? Thanks, Avi Why would you do this? The respond_with method is used to initialize a responder, which will only set the path to go to. If u need an association, you must do this on your where call. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br . Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- - Paulo Henrique Lopes Ribeiro Graduando em Ciência da Computação pela UNIFEI http://www.unifei.edu.br. Web Developer na Zertico http://www.zertico.com - Ruby, Ruby on Rails, PHP, HTML, CSS. Linux - Debian Lenny/Squeeze/Wheezy amd64(XEN) - Centos 5.5 x86_64 -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups Ruby on Rails: Talk group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.