Does the example repository in this cast work anymore? I downloaded the code from GitHub and ran the "checklist-after" and the request for a new task reloaded the whole page, not just the form with AJAX.
Is this a little dangerous even with receiving a default param from routes table? Is it possible for end user to set ?commentable='arbitrary_class' in a request to create object of any class?
I'm having a problem when I try to import a csv file with more than one column. I get a mass assignment security error in spite of the fact that I have all the attributes listed in my attar_accessible statement. The error seems to list all the attributes except the very first column of my csv file. Any ideas? My code is the same as Ryan's with the exception that I am using a model named "Customer.rb" instead of "Product.rb"
Im using devise with Rails 4 and im getting an error in my log file trying to sign in.
Unpermitted parameters: password, remember_me
I have this code in my app controller:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
If you are having a problem with the dynamic add/remove javascript not working I found a solution. The problem for me was the rake gem. My solution was to require rake 0.9.2.2 in gemfile then run "bundle update" to rebuild gems from scratch.
Perhaps more experienced Rails users know this... After adding the Mime::Type.register_alias "text/html", :mobile I got undefined methodref' for nil:NilClass` when trying to go to the mobile site. When I restarted my local rails server, the error went away.
How can I list specific tags in route file? I want to create a link and filter specific tags. I want to be able to link the path to specific filtered tags for my posts using link_to. e.g. <%= link_to "Blog", posts_path %>
ruby
puts "
get 'tags/:tag', to: 'posts#index', as: :tag"
Update: To make this work in XLS format, we need to pass in the tab character, so I modified my controller to look like this:
ruby
@products = Product.find_all_by_color("green")
respond_to do |format|
format.csv { send_data Product.to_csv({},@products) }
format.xls { send_data Product.to_csv({col_sep:"\t"}, @products) }
end
And then this is how product.rb receives the call of .to_csv with the tab character and @products passed in as variables from the controller:
def self.to_csv(options,products)
CSV.generate(options) do |csv|
csv << column_names
products.each do |product|
csv << product.attributes.values_at(*column_names)
end
end
end
When I upgraded to Rails 3.2 I had issues with running the seed tasks, only in production. When the seed file ran, it would not find any ActiveRecord models; but would work fine when called from the console.
Turns out, threadsafe was enabled in production, and rake tasks would get tripped up. To fix I had to do:
Thanks for gem.I have success fully completed all the thing.But at last I stuck.
I am using private chat 1-1 user.
When user starts chat, it works fine.But if user close his window(like facebook).and again clicks on start button ,then he gets two time same message.and if again he close than he gets 4 time same message.finally I fond the error, subscribe_to create same channel when window is open.and it published message 2 times.I tried to handle this things a lot from my side still I am getting problem.
how can I check whether channel it is exist or not.or any other solution for that.
@Dennis I'd also like to know this. I'm new to Rails and looking for the best way to populate my DB with fake data. Rails seems to have come a long way, so I'd like to be sure.
I noticed this screencast is pretty old. As some have mentioned, there's a faster faker (ffaker) now.
When I search through repos on GitHub, I noticed a lot of people are using the ffaker gem in their specs/ directory.
I'm new to Rails, and I'm not familiar with the specs/ directory yet. Is the info in this screencast still a good way to populate your DB with random fake data?
Not a rails expert, but found the solution for anyone else with the issue. Rails 4 now uses strong params with protecting attributes now done in the controller
ruby
...
defcreate
respond_with Entry.create(entry_params)
enddefupdate
respond_with Entry.update(params[:id], entry_params)
end
...
defentry_params
params.require(:entry).permit(:name, :winner)
end
...
@chris, I am trying to limit the answer to one, did you find a way to prevent the Add Answers link from being rendered if we already have reached our limit?
Notice they changed to sets of hashes for options. One hash of options for the Redcarpet::Render::HTML.new(options hash here)
and the second options hash for the Redcarpet::Markdown.new(renderer(this is where the renderer goes), markdown hash here). To understand, here are both without removing options into two variables.
ruby
defmarkdown(blogtext)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new({hard_wrap:true, filter_html:true}), {autolink:true, no_intra_emphasis:true})
markdown.render(blogtext).htm_safe
end
Check their github site to find out which options belongs in which options hash.
Just wanted to point out that I'm working on a gem called "Headhunter" that overtakes Deadweight's functionality and also validates HTML and CSS all in one automagically in your Rails app. For this, it injects itself as middleware into the Rack stack and validates every HTML response that any feature tests triggers.
Hey, is it possible for pgSearch to search whole phrases? If I have a text called "On Hold" and a text called "On Hold - later", I want the search result to return only "On Hold" if the search term is "On Hold".
Actually I got that wrong... Here is the code that worked for me. Again the link I put in the initial response was where I got this code...
Products Controller
def product_params
params.require(:product).permit(:name, :product_type_id).tap do |whitelisted|
whitelisted[:properties] = params[:product][:properties]
end
Hi, are these instructions still current? Are they meant to work with Rails 4? I have devise, omniauth and have separate user and authentication models. I'm trying to follow along with this but am not getting the results being demonstrated. Is it possible that this is no longer current? Thank you, OH
I am using Rails 4, and instead of: rails generate acts_as_taggable_on:migration,
I have to use: rake acts_as_taggable_on_engine:install:migrations.
But I want to remove this rake acts_as_taggable_on_engine:install:migrations that I did, but I can't find anywhere how to do this
Did you find a solution to this problem? I am having the same issue with 4.0.2
Hey,
Does the example repository in this cast work anymore? I downloaded the code from GitHub and ran the "checklist-after" and the request for a new task reloaded the whole page, not just the form with AJAX.
Cheers
How would you do model validation to ensure that user must add at least one field?
Update:
http://blog.remarkablelabs.com/2012/12/strong-parameters-rails-4-countdown-to-2013
Please note that for non-US payments payment_fee and payment_gross fields are not populated. You have to take values from mc_fee and mc_gross instead
Hi, can you do a more recent episode on devise?
i'm getting trouble with the partial.
undefined local variable or method `target' for #<#Class:0x00000003f702d0:0x00000002599460>
the form:
The partial have the same code...
but if this code is directly in the form it's working...
but i want to work with the partial...
Is this a little dangerous even with receiving a default param from routes table? Is it possible for end user to set ?commentable='arbitrary_class' in a request to create object of any class?
Thank you, it was very helpful! Going to try Nested forms gem right now.
Great comments, especially Sergey and Adrian's comments helped me get mine working. I put a clear winner button. Here's the code:
raffler.js.coffee
index.html.rb
I figured out my problem. I had spaces after the commas in my csv file. Once removed, I no longer had the problem.
I'm having a problem when I try to import a csv file with more than one column. I get a mass assignment security error in spite of the fact that I have all the attributes listed in my attar_accessible statement. The error seems to list all the attributes except the very first column of my csv file. Any ideas? My code is the same as Ryan's with the exception that I am using a model named "Customer.rb" instead of "Product.rb"
Hi, I would you someone can help me.
Im using devise with Rails 4 and im getting an error in my log file trying to sign in.
Unpermitted parameters: password, remember_me
I have this code in my app controller:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, :username) }
end
end
Hope you can help me. Thank you!
If you are having a problem with the dynamic add/remove javascript not working I found a solution. The problem for me was the rake gem. My solution was to require rake 0.9.2.2 in gemfile then run "bundle update" to rebuild gems from scratch.
Thanks for the suggestion Allen. This fixed my unicorn deploy woes and seems to be pretty clean.
I added these tasks:
And then these hooks:
It actually does, but since it becomes unstickied it moves down the list.
Perhaps more experienced Rails users know this... After adding the
Mime::Type.register_alias "text/html", :mobile
I gotundefined method
ref' for nil:NilClass` when trying to go to the mobile site. When I restarted my local rails server, the error went away.Beware, cause this is now deprecated: Rails 4 release notes
How can I list specific tags in route file? I want to create a link and filter specific tags. I want to be able to link the path to specific filtered tags for my posts using link_to. e.g. <%= link_to "Blog", posts_path %>
puts " get 'tags/:tag', to: 'posts#index', as: :tag"
Awesome gem! I'm a new Rails user and always thought that the error output was ugly and not at all very helpful. Thanks a bunch!
Update: To make this work in XLS format, we need to pass in the tab character, so I modified my controller to look like this:
And then this is how product.rb receives the call of .to_csv with the tab character and @products passed in as variables from the controller:
When I upgraded to Rails 3.2 I had issues with running the seed tasks, only in production. When the seed file ran, it would not find any ActiveRecord models; but would work fine when called from the console.
Turns out, threadsafe was enabled in production, and rake tasks would get tripped up. To fix I had to do:
also a good thing for capistrano recipes.
I am having the same error, even when I test with an Administrator account. :-(
Any idea?
Hello,
Thanks for gem.I have success fully completed all the thing.But at last I stuck.
I am using private chat 1-1 user.
When user starts chat, it works fine.But if user close his window(like facebook).and again clicks on start button ,then he gets two time same message.and if again he close than he gets 4 time same message.finally I fond the error, subscribe_to create same channel when window is open.and it published message 2 times.I tried to handle this things a lot from my side still I am getting problem.
how can I check whether channel it is exist or not.or any other solution for that.
Please help me for that.
Thaks
Arun
@Dennis I'd also like to know this. I'm new to Rails and looking for the best way to populate my DB with fake data. Rails seems to have come a long way, so I'd like to be sure.
Just solved this - it's a problem between turbolinks and jQuery UI. Installed this gem, problem disappeared.
https://github.com/kossnocorp/jquery.turbolinks
Hey Mihai - I'm having the same issue (but I'm using Bootstrap, not ZURB). Did you ever figure out what the problem was?
I noticed this screencast is pretty old. As some have mentioned, there's a faster faker (ffaker) now.
When I search through repos on GitHub, I noticed a lot of people are using the ffaker gem in their specs/ directory.
I'm new to Rails, and I'm not familiar with the specs/ directory yet. Is the info in this screencast still a good way to populate your DB with random fake data?
Not a rails expert, but found the solution for anyone else with the issue. Rails 4 now uses strong params with protecting attributes now done in the controller
i keep coming back to this screencast; the best screencast on TDD i've seen so far.
Solve by unicorn stop and then unicorn start instead of restart.
Great vid mate, however using Rails 4 I'm getting the following error on my create and update methods:
ActiveModel::ForbiddenAttributesError
@chris, I am trying to limit the answer to one, did you find a way to prevent the Add Answers link from being rendered if we already have reached our limit?
Alternatively, set the default format in the routes.rb file:
did you get this to work? and how?
I am using Rails 4
@branden, did you get an answer for this? I want to use has_one and belongs_to relationship for question-answer. and it is not working
please can some one help me with this problem here? I am using rails 4. http://stackoverflow.com/questions/21295989/nested-attributesmodels-forms-not-working-as-needed-in-rails-4
I want to use a has_one relationship for questions-answer.
Thanks
Solved... It was just a stupid typo.... Sorry guys..
Update for anyone using RedCarpet 3.0.0
Using this RailsCast, just change the helper method to this:
Then in view just use
<%= markdown(@blog.body) %>
Notice they changed to sets of hashes for options. One hash of options for the Redcarpet::Render::HTML.new(options hash here)
and the second options hash for the Redcarpet::Markdown.new(renderer(this is where the renderer goes), markdown hash here). To understand, here are both without removing options into two variables.
Check their github site to find out which options belongs in which options hash.
Just wanted to point out that I'm working on a gem called "Headhunter" that overtakes Deadweight's functionality and also validates HTML and CSS all in one automagically in your Rails app. For this, it injects itself as middleware into the Rack stack and validates every HTML response that any feature tests triggers.
It would be great to get some feedback, check it out! https://github.com/jmuheim/headhunter
Do you solve this problem? I have the same one.
Hey, is it possible for pgSearch to search whole phrases? If I have a text called "On Hold" and a text called "On Hold - later", I want the search result to return only "On Hold" if the search term is "On Hold".
Is this possible? Thanks in advance!
Actually I got that wrong... Here is the code that worked for me. Again the link I put in the initial response was where I got this code...
Photo.create( params)
From my understanding you have to use tap and then whitelist the dynamic fields. Here is the code I used in my application.
Here is the resource I used to figure this out.
Link
I hope that helps.
I know this is a little late but I recently released a gem for this exactly this purpose. Do check out Cadinsor.
Awesome!!! Thanks for the blog post.
Hi, are these instructions still current? Are they meant to work with Rails 4? I have devise, omniauth and have separate user and authentication models. I'm trying to follow along with this but am not getting the results being demonstrated. Is it possible that this is no longer current? Thank you, OH
I am having the same issue, and still not clear how you resolved it, can you paste your before and after code?
Thanks!