Since I've started using Draper, I've generally been pretty happy with it. The one thing that keeps biting me is object equality (decorated_object != object) and in general code that expects to be dealing with an actual instance of the model class and not an instance of the decorator behaves differently or incorrectly when your object isn't actually an instance of your model class.
If @user is a UserDecorator object and current_user is a User object, for example, then even a simple test like this:
ruby
if@user == current_user
...
end
doesn't work as expected.
Have also had some occasional odd behavior when working with CanCan. (To get error messages to work as expected, for example I had to add a section for user_decorator: in addition to user: in my locale file because it looks up messages based on the object's class.)
I wish Draper worked by mixing in a module instead of creating a an entirely new class. Then a decorated User object, for example, would still be a User and object equality would work as expected.
But I guess Draper was only intended to be used in the view layer, so my mistake was probably that I am decorating objects in the controller as soon as I fetch them from the database. Maybe I will try to only create and use the decorated objects in the view and see if that works any better...
A Newbie question. If a user typed a misspelled or mistype word e.g graphc rather than graphic, will it still give some result. What's the best way to handle that kind of situation as i can't find any plugin for "did you mean? graphic" functionality.
first of all thanks to Ryan for a great RailsCast again and thanks to Sam for this wonderful gem.
No problem with installing the gem as expected. But I also do not see any SQL query times while profiling in development mode. Here's my setup:
ruby-1.9.3-p194 [ x86_64 ]
Using rails (3.2.8)
Using rack (1.4.1)
Using sqlite3 (1.3.6) for development
Using pg (0.14.1) for production (no MySQL gem)
Using newrelic_rpm (3.4.2)
Using thin (1.4.1)
I would imagine Rails 4 handles it a lot better once it's released.
The great thing about this is you get the benefits of schemaless data with your schema'd data... and you get to keep using AR.
Yes! There is a way to compile Ruby to Java...try to type 'jrubyc' in the shell...it simply takes Ruby files and converto to java .class
If you want a compiled version of your Rails app try:
Works great for me, but the cucumber test fails. I get “Password can't be blank” messages. I guess it is related with using “:without_protection => true” while creating new User.
step_definitions/user_steps.rb
defset_facebook_omniauth
credentials = {:provider => :facebook, :uuid => '65', :info => {:email => 'machete@yourgarganta.mx', :name => 'Denny Trejo'}}
OmniAuth.config.test_mode = trueOmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({'uid' => credentials[:uuid], 'info' => {'email' => credentials[:info][:email], 'name' => credentials[:info][:name]}})
endWhen/^I login with Facebook$/do
set_facebook_omniauth
visit root_path
click_link 'Login with Facebook'endThen/^I see a successful sign in message$/do
page.should have_content "Signed in successfully."end
As I’m using mongoid I’ve changed a bit “from_omniauth” method.
I've successed to deploy my private_sub app to heroku today
I'dont understand about rack application yet
anyway, for Faye server in Gemfile I added 3gems , private_pub, thin, and foreman
and make file 'Procfile' in rails root, like this
then git push heroku master as usual, and done
When you access faye server address, if you show message 'Sure you're not looking for /faye ?' ,
faye server is good working.
If you're using twitter-bootstrap-rails gem sumply update your gemfile by running bundle update run the install task for the gem once again and then if you're using the asset pipeline you can run rake assets:precompile. If that doesn't work go to the official gem repository they have a link to their mailing list where you can ask them directly.
Are you saying you set :attr_accessible nil and it won't let you assign any attributes? If that's the case, just manually set them when necessary. New/create/build take a block form so you can do this somewhat nicely:
Something.create(params[:something]) do |thing|
thing.attr = params[:something][:attr]
end
while I realize that seems silly, it's better than the alternative :)
Are you saying you set :attr_accessible nil and it won't let you assign any attributes? If that's the case, just manually set them when necessary. New/create/build take a block form so you can do this somewhat nicely:
Something.create(params[:something]) do |thing|
thing.attr = params[:something][:attr]
end
while I realize that seems silly, it's better than the alternative :)
That seems pretty well organized. But then, if you have a dozen helper files and access them from a dozen different views, then if you are looking in the view and you see a call to a method, you really have no idea where it is defined, and most people use their IDE to find it. And what happens if you use the same name for a method in each of 2 different helper modules?
And these helper methods are for views, anyway, not for controllers, so I don't think it is very nice to have to include them in the controller. I think it would be much better if we were including them in the views, or perhaps just calling them with their module name and method name.
Is anyone else underwhelmed by the way the helpers work?
Hi
I tried this gem today
if you follow this video, your faye server :9292 is in production env, but your rails server :3000 is in development env.
so when you access from remote anything but localhost, you describe your faye server address in "config/private_pub.yml".
like this....
development:
server: "http://192.168.1.20:9292/faye"
secret_token: "secret"
Thanks for this screencast, during my migration to chef-solo I started working on a solution which makes it super easy to install a more or less standard rails stack so that you can start deploying via capistrano:
Really a great technique. Rather than using a querystring param, I choose to use the URL extension. It just felt better than a querystring since Rails already responds to that to determine the correct MIME format:
This works on Mac OS because of the commonly case-insensitive filesystem, but once you deploy on a linux server, the all small-caps won't function correctly. Took me a while to figure out this discrepancy.
Ryan, you can use <<-RUBY instead to get highlighted heredoc in Textmate.
Since I've started using Draper, I've generally been pretty happy with it. The one thing that keeps biting me is object equality (
decorated_object != object
) and in general code that expects to be dealing with an actual instance of the model class and not an instance of the decorator behaves differently or incorrectly when your object isn't actually an instance of your model class.If
@user
is aUserDecorator
object andcurrent_user
is aUser
object, for example, then even a simple test like this:doesn't work as expected.
Have also had some occasional odd behavior when working with CanCan. (To get error messages to work as expected, for example I had to add a section for
user_decorator:
in addition touser:
in my locale file because it looks up messages based on the object's class.)I wish Draper worked by mixing in a module instead of creating a an entirely new class. Then a decorated
User
object, for example, would still be aUser
and object equality would work as expected.But I guess Draper was only intended to be used in the view layer, so my mistake was probably that I am decorating objects in the controller as soon as I fetch them from the database. Maybe I will try to only create and use the decorated objects in the view and see if that works any better...
Thnx your solution works for my Dutch website where I rename my resources to Dutch words like so:
resources :users, :path => "gebruikers" do
resources :comments
end
A Newbie question. If a user typed a misspelled or mistype word e.g graphc rather than graphic, will it still give some result. What's the best way to handle that kind of situation as i can't find any plugin for "did you mean? graphic" functionality.
Hi there,
first of all thanks to Ryan for a great RailsCast again and thanks to Sam for this wonderful gem.
No problem with installing the gem as expected. But I also do not see any SQL query times while profiling in development mode. Here's my setup:
ruby-1.9.3-p194 [ x86_64 ]
Using rails (3.2.8)
Using rack (1.4.1)
Using sqlite3 (1.3.6) for development
Using pg (0.14.1) for production (no MySQL gem)
Using newrelic_rpm (3.4.2)
Using thin (1.4.1)
Any progress in examining this issue? Do you want me to post this question / issue on http://community.miniprofiler.com ?
Thanks a lot
Andy
I would imagine Rails 4 handles it a lot better once it's released.
The great thing about this is you get the benefits of schemaless data with your schema'd data... and you get to keep using AR.
Thanks! It works now!
Seems like you missed 'provider' in your mock.
Yes! There is a way to compile Ruby to Java...try to type 'jrubyc' in the shell...it simply takes Ruby files and converto to java .class
If you want a compiled version of your Rails app try:
$ warble compiled war
Works great for me, but the cucumber test fails. I get “Password can't be blank” messages. I guess it is related with using “:without_protection => true” while creating new User.
As I’m using mongoid I’ve changed a bit “from_omniauth” method.
I've successed to deploy my private_sub app to heroku today
I'dont understand about rack application yet
anyway, for Faye server in Gemfile I added 3gems , private_pub, thin, and foreman
and make file 'Procfile' in rails root, like this
then git push heroku master as usual, and done
When you access faye server address, if you show message 'Sure you're not looking for /faye ?' ,
faye server is good working.
Can anyone describe how FnordMetric compares/contrasts to graphite-statsd??
Should also have "set :normalize_asset_timestamps, false" in deploy.rb
They're different creatures. Squeel is a DSL that works with ActiveRecord -- Sequel is an entirely different ORM.
If you're using twitter-bootstrap-rails gem sumply update your gemfile by running bundle update run the install task for the gem once again and then if you're using the asset pipeline you can run rake assets:precompile. If that doesn't work go to the official gem repository they have a link to their mailing list where you can ask them directly.
I was hoping so, but all I can see is Reply. It appears you can only Delete within a certain timeframe.
Are you saying you set :attr_accessible nil and it won't let you assign any attributes? If that's the case, just manually set them when necessary. New/create/build take a block form so you can do this somewhat nicely:
while I realize that seems silly, it's better than the alternative :)
Are you saying you set :attr_accessible nil and it won't let you assign any attributes? If that's the case, just manually set them when necessary. New/create/build take a block form so you can do this somewhat nicely:
while I realize that seems silly, it's better than the alternative :)
That seems pretty well organized. But then, if you have a dozen helper files and access them from a dozen different views, then if you are looking in the view and you see a call to a method, you really have no idea where it is defined, and most people use their IDE to find it. And what happens if you use the same name for a method in each of 2 different helper modules?
And these helper methods are for views, anyway, not for controllers, so I don't think it is very nice to have to include them in the controller. I think it would be much better if we were including them in the views, or perhaps just calling them with their module name and method name.
Is anyone else underwhelmed by the way the helpers work?
God might work for you. http://godrb.com/
Hi
I tried this gem today
if you follow this video, your faye server :9292 is in production env, but your rails server :3000 is in development env.
so when you access from remote anything but localhost, you describe your faye server address in "config/private_pub.yml".
like this....
development:
server: "http://192.168.1.20:9292/faye"
secret_token: "secret"
i hope it will be help
FYI, I just wrote about my experience with Compass and CSS Sprites. Check it out here.
Hi there,
can someone offer this tutorial as a "non-square-thumbnail" example?
I ran into render issues when I try to change the parameters to a "rectangle" in the js.coffee file
Thank you!
Is it possible to use this to make a review system? For example: Have a five star rating system with comments/text belonging to each vote?
Cool but doesn't work if you mix new and existing records.
+1
I usually use friendly_id gem too.
I am going to integrate the event tracking into my system. Will this lead to some performance issue when real time access increased sharply?
For local development you can use the domain http://lvh.me. Some kind soul purchased it and pointed it to localhost.
Thanks for this screencast, during my migration to chef-solo I started working on a solution which makes it super easy to install a more or less standard rails stack so that you can start deploying via capistrano:
https://github.com/dei79/solify
Really a great technique. Rather than using a querystring param, I choose to use the URL extension. It just felt better than a querystring since Rails already responds to that to determine the correct MIME format:
I see that fnordmetric is namespacing redis. Can this be easily integrated with resque using the same redis instance?
Does Squeel support hstore?
Is there a good way to implement this functionality?
Does anyone know whether and if so how it's possible to use fnordmetric on heroku?
There's also Image Sorcery, which allows you to directly use the ImageMagick command line tools.
You don't have to. If you're not using strong_parameters, just use
:without_protection => true
. See the last example at http://api.rubyonrails.org/classes/ActiveRecord/AttributeAssignment.html#method-i-assign_attributesIf you're using Pow.cx, you could define these in .powenv file. If you're using foreman, you could define it in .env file in your app directory
This is happening to me. Very frustrating.
Does this make performance faster than erb or its all about how to make your own template? nice screen cast.
There is a little information about doing so here: https://github.com/paulasmuth/fnordmetric/issues/60
I've just now asked for an example / gist
Interesting screencast. Could it be a mountable engine? Is possible to protect it with authentication?
I'm using draper and in my controller's index action, i have following code
and in my view
and I have a partial, _post.html.erb
I want to access methods defined in PostDecorator and UserDecorator in my partial
like
post.post_title
What should i need to do to pass @posts variable into my _post partial and access decorator methods
I tried following but failed
<%= render @posts, locals: { post: @posts} %>
and
<%= render @posts, object: @posts %>
Please help me
Thanks :)
ah I was looking for this for half a day! :) Thank you!!
I think it's not convenient to debug in action of rails, because there's no list, step, next method, while we can't call an action directly.
You could just:
request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i
Rather than going through each individually and you can ignore case.
Nice. I recently did something like this, but I used the friendly_id gem instead for the friendly url stuff. Nice info nonetheless.
Does anyone know how to change default jvm options (heap size, stack size) that trinidad_init_services uses to generate init script ?
Possible that this is due to my out of date (but unupdateable) rubygems!
Hey Ryan, an important heads-up!
You actually need to do
require "RMagick"
and not
require "rmagick"
This works on Mac OS because of the commonly case-insensitive filesystem, but once you deploy on a linux server, the all small-caps won't function correctly. Took me a while to figure out this discrepancy.
Does creating a new category belong in the model? - It seems a bit weird to have it in the model rather than the controller, or is it just me?