How does this translate to Rails 3.1?
#template.instance_variable_get(:#_first_render).name
It's supposed to output the name of the view being rendered. Note: it's not always the same as params[:action]
Thanks!
You can find one great answer for Rails 3.0.X here.
There is another for Rails 3.1.x but I tried it without success.
Related
Trying override the default rspec-rails scaffold generator template for controllers but for some reason the new template isn't getting picked up
/lib/templates/rspec/scaffold/controller_spec.rb
Apparently putting it there should just work but it still doesn't show when running rails g rspec:scaffold.
Did the format change? I'm using Rails 4.2.2 and rspec-rails 3.3.3
A quick search on google revealed this one: https://github.com/rspec/rspec-rails/blob/master/lib/generators/rspec/scaffold/templates/controller_spec.rb
Which lives under lib/generators/spec/scaffold/templates/controller_spec.rb. Perhaps your source for the location is wrong?
I'm updating an old rails 2 app to rails 4. In the view there is a form field defined like this:
school[existing_address_attributes][666][city]
The model is updated as normal in the controller:
#school.update_attributes(params[:school])
The form works, and submits and saves properly, but I can't tell where existing_address_attributes is defined.
This seems to work similarly to nested attributes. Is this native to rails? Is it some gem? What am I missing?
This is most probably defined by accepts_nested_attributes_for. Check the Rails 2 documentation.
I have migrated from Rails3 to Rails4. The following code returns Array in Rails3 but in Rails4 it returns string with illegal character.
Dir.glob("app/assets/images/flowers/*")
sample output in Rails3
["app/assets/images/flowers/rose.png", "app/assets/images/flowers/lilly.png"]
output in Rails4
"\x04\b[dI\"8app/assets/images/flowers/rose.png\x06:\x06ETI\"4app/assets/images/flowers/lilly.png"
How to get same output format as in Rails3?
try this
files = Dir.glob("app/assets/images/flowers/*").map do |f| File.basename f end
Dir has nothing to do with Rails — it's pure Ruby class. Here is the API reference to it. According to API it should always return an Array. My guess is that you messed up something in your Ruby installation while you were upgrading Rails 3 to 4.
I think best bet will be a clean installation of ruby/rails. You could also try to run Dir.glob() from both IRB and rails console to see where the mistake happens; and start from there.
It's probably me getting the wrong end of the stick, but here goes..
Following the Ruby on Rails tutorial here http://guides.rubyonrails.org/getting_started.html
(Ruby 2.0.0, Rails 4.0)
All good until I get to this section here:
If that's a route entry as the text suggests, then it doesn't look like the right syntax to me. I can make it work by changing it to this..
get '/posts/:id(.:format)' => 'post#show'
...haaang on... (penny drops)
Looking at it as I type this, it looks like the tutorial is showing the output of the rake routes command and expecting me to translate it to the valid route entry syntax?
(Given the copy/paste nature of the rest of the tutorial isn't that a little confusing for Ruby/Rails noobs like myself?)
Same question, different answer here Rails getting started 5.7
I guess that the doc needs some updating, since before it tells you to add
resources :posts
to your routes.rb configuration file, which should automatically add all 7 rest routes for you.
The guide tells you that the show action is absent in your controller. I think that the whole sentence should be reworded :)
I'm upgrading my project to rails 3.0.1 , i have used paginate_all_by_something in the controller in rails 2.1.1 and rails 2.3.8 working fine but in rails 3.0.1 it displaying the undefined method `paginate_all_by_receiver_deleted' for #
error like this
If anybody faced like this problem kindly help me.
It might be because of backwards incompatibility of new version of will_paginate (~>3.0).
Read here for further details.
You can use paginate on collections instead like this:
User.find_all_by_receiver( receiver_id ).paginate
So it's up to you how you construct the collections.