[Rails] Re: Instance variable looses value upon render
Oh, I really got this wrong. So, the HTML is already constructed with the render call, then the rest of the action is executed! Thanks a lot. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/93d488d0f229a07833503fde046f5031%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Instance variable looses value upon render
I have an instance variable, @pages, which needs to be set up in a certain way at the end of several actions, so I thought to be clever and do it in the following way: # In my controller after_action :prepare_admin_home_data, only: [:adm_login,:adm_upload_selected] def adm_login ... render admin_pages_home_path ... end def prepare_admin_home_data @pages=Dir[#{AMP_DIR}/*] logger.debug(+++ pages #{@pages.to_s}) end I can see from the logs, that @pages got the right value, but in my view, it is nil. It seems that the HTML code is constructed before the after_action is executed. I understood the render() function in that way, that it only sets up which ERB template is supposed to be used, but actual rendering would occur only when the action has finished. Did I get this wrong? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/e7404664c6e1b81a2d21344b175ad484%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Forgot to define action - but no error! How is this possible?
One of my routes looks like this: admin_pages_home GET/admin_pages/home(.:format) admin_pages#home In one of my views, I have a link to admin_pages_home_path, and clicking on this link indeed works and renders admin_pages/home.html.erb, as we can see from the logfile: Started GET /admin_pages/home for 127.0.0.1 at 2014-09-08 15:32:41 +0200 Processing by AdminPagesController#home as HTML Rendered admin_pages/home.html.erb within layouts/application (7.6ms) Now, the weird thing here is that I had forgotten to define a home() function in AdminPagesController (and I also didn't put one in ApplicationController). Actually, the only other home method I have is in a completely unrelated controller. I wonder how it can be, that clicking on the admin_pages_home_path link, didn't raise an exception. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/8a99e998a76916b3955e2782e58ad2d0%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Forgot to define action - but no error! How is this possible?
Muskalek wrote in post #1157141: This is expected behaviour. I see! Thank you for pointing it out! At times, the plethora of automatisms found in Rails is a bit creepy I always had the habit to explicitly define my actions, so I didn't stumble over this one earlier. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/a54d5eec6fad38a42f7cac256e01caa9%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: is_a? returns false, though I think it should return true
Iazel wrote in post #1157000: However, if you still don't like this, you can just check if the last parameter is a Fixnum (duck typing style) and act accordingly: x = n.respond_to?(:to_int) ? n.to_int : g(c) Isn't this a bit risky? After all, Card the class of n derives from ActiveRecord::Base, i.e. a class, which I can't control. Now imagine that in a new version of Rails, this class would receive a to_int method (for example, to implicitly convert a model object into the id of the object). This would break my code. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/0512827d7d5bb137f82314654cd5da17%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Password filtering does not work
Hassan Schroeder wrote in post #1156593: On Tue, Sep 2, 2014 at 5:26 AM, Ronald Fischer li...@ruby-forum.com wrote: In my Rails 4 application, when I have a form including a password, i.e. I don't like the fact that the password is shown plain text in the log file, and would like to disable this. How can I do this correctly? Hint: look at your initializers. Thanks, that was it! Just for the record: The default content of config/initializers/filter_parameter_logging.rb (which was probably generated automatically with my rails application) is Rails.application.config.filter_parameters += [:password] Since my password field is named differently, I had to add it to this list: Rails.application.config.filter_parameters += [:password,:admpwd] -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/32e0e3f806a494b8524ab1b20fbb13ae%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Password filtering does not work
In my Rails 4 application, when I have a form including a password, i.e. %= password_field_tag 'admpwd', nil, size:32, maxlength: 32, class: 'admentry' % I don't like the fact that the password is shown plain text in the log file, and would like to disable this. I found several suggestions to place the call filter_parameter_logging password into application.rb, but when I do it, I get the error message undefined method `filter_parameter_logging' for Tamsin::Application:Class How can I do this correctly? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/a7f3ac73e71e2b37a32775c087784c37%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: is_a? returns false, though I think it should return true
This hints at design flaws within your application. I suspect this too, though I can't see a *convincing* better solution. I try to sketch my problem in an abstract way: I have a function f which, when receiving a Card object, can find a certain integer number which it then uses for further calculation: def f(a,b,c) x=g(c) # c is a Card, x is a positive integer ... # do something with a, b, x end Occasionally, I am calling f in a loop, and I know from the context (I could actually make this an assertion) that g(c) MUST be the same in each iteration, even though the c is sometimes different. Hence I want to precompute the value of g(c) and pass the integer to f. If it were C++, I would implement this providing to overloaded definitions of f. As for Ruby, I see so far four possibilities: (1) Query the type of c at runtime (2) Require, that c is an integer, and calculate g(c) always at the calling site, i.e. f(a,b,g(c)) (3) Provide two differently named functions, one expecting a Card and one expecting an integer. (4) Make g a method of Card, and add a g method to Fixnum, which just returns the number unchanged. I agree with you, that (1) is ugly, because we don't want to do runtime tests. I don't like (2) and (3) either, because it makes f more inconvenient to use. (4) has the advantage, that we can write inside f simply: x=c.g This would be duck typing at work, but extending such a basic class as Fixnum by a function, which doesn't have any semantic on its own, doesn't look like good design either. What approach would you suggest? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/3861fb8069c27c0c215f235cf524c10c%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] is_a? returns false, though I think it should return true
Rails 4, Ruby 2 Model has Card and Idiom and Idiom belongs_to :card In my Rails console I have an Idiom i and get the card from it: c=i.card = #Card id: 19, Now I do: c.is_a?(Card) = false c.instance_of?(Card) = false Ooops! Why false in both cases? c.class.name = Card c.class.name==Card.name = true The class name is the same, but the class isn't? Please explain And now an explanation why I want to do it: I have a function which is overloaded, in that it's single argument can be either of a certain clas (in my case, Card (or a subclass of it)), or a Fixnum, and I need to distinguish between these cases. I know that it is not the best style of querying the type of a variable at runtime, but the only alternatives I could think of, would be to either provide two differently named functions, or have an hash argument with two types of keywords, and I don't like both of these solutions. Aside from this, I'm really curious to know why is_a? doesn't work here. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/57d76f799458f02d7a4c9494c08bc909%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: is_a? returns false, though I think it should return true
This certainly sounds reasonable, not rubbish at all. I think I was begging for trouble when I wanted to test the class membership, which certainly is not in spirit with ActiveRecord and/or Duck Typing OOP I guess the solution I'm trying is too dirty, and I just was bitten by it. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/bf1967dadc2077efb38fa08be98959ad%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Design Question: User-managed static pages
I'm creating a web site for a user, which has a considerable amount of static pages. The user, who has some knowledge in HTML and CSS and can be tought how to use some simple erb-code snippets (for example, to create a %= link_to ...,root_path %), should be able to add, change and remove the static pages by himself. I will describe the approach I came up with, but would be glad to hear better ways how to do it: My approach would be to use high_voltage (https://github.com/thoughtbot/high_voltage) for dealing with those pages. I would reserve a directory app/views/user_pages for the HTML and erb files, and app/views/images/user for holding the images needed for his pages. The user will be told to upload by FTP only to those two directories (or I will provide a specially tailored upload page for this). I will also create an admin page, where the user can select, which of those static pages should show up in the main menu, and maybe also some sequence number for each page, so that the user also can control the sequence of the static page links in the main toolbar. This allows the user to first test how the static pages look on the net, before he commits them to the general public. This will be important, if he really uses %...% tags, because he won't have a Rails environment when creating the pages. What do you think about this design? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/0ad8e05840a3a9377fada27ea9c91a60%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Issues with catenating the results of two queries + will_paginate
(Rails 4, Ruby 2) I have two functions which query the database. Both yield a set of model objects. These two sets should be catenated and presented to the user using the will_paginate Gem. I think I understand now how to do it, but a few issues with this are still puzzling me. Here are the query functions: def the_other_dicts_of_same_user(d) User.find_by_id(d.user_id).dicts.where(id != #{d.id}) end def public_dicts_of_other_users(d) Dict.where(user_id != #{d.user_id} and world_readable) end Both yield a series of Dict objects. The result of the first query is of type Dict::ActiveRecord_AssociationRelation and the result of the second query is of type Dict::ActiveRecord_Relation I guess I get different data types here, because I start with User in the first case and with Dict in the second case. As a side note: I *could* have written the first query alternatively as Dict.where(user_id = #{d.user_id} and id != #{d.user_id}) Would this be better? Anyway, I catenate the results, @dicts=the_other_dicts_of_same_user(d)+public_dicts_of_other_users(d) which yields again a Dict::ActiveRecord_Relation . Now I apply pagination: @dicts=@dicts.paginate() This yields the error message, that paginate is not defined for objects of type Array. I was able to get around this error, by doing a require 'will_paginate/array' as a first line in my controller, but I wonder: Why do I get this error? @dicts is NOT an array (I logged @dicts.class.to_s to be sure of this), and I would have expected to work it in a ActiveRecord_Relation. Could someone please kindly explain this observed behaviour to me? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d85f9c9847591cb08260ea24d7f84554%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Issues with catenating the results of two queries + will_paginate
Walter Davis wrote in post #1155317: But adding the two together must (I am guessing here) cause them to both be evaluated as arrays before the addition can succeed. I don't think this is the case. As I said, I also logged the object AFTER adding them together, and it still is a Dict::ActiveRecord_Relation. The conversion into an Array must come after that, and this means it must happen inside paginate(). Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/88b28ae3f6e5c76efda84466ad54dd37%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Issues with catenating the results of two queries + will_paginate
Colin Law wrote in post #1155319: On 16 August 2014 11:03, Ronald Fischer li...@ruby-forum.com wrote: Would it be possible to combine the two queries into one - Dict.where( ... or ... )? Then you would not need to concatenate them. Technically, yes, and it likely would be a performance improvement too. From a designer's viewpoint, I don't like this solution so much, because the individual parts are used in different contexts too, and it means I would have code duplication here, but maybe I will give it a try. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f36a8039a96f3275ff1926a9fee19a63%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Issues with catenating the results of two queries + will_paginate
Walter Davis wrote in post #1155322: On Aug 16, 2014, at 9:42 AM, Ronald Fischer wrote: Walter Davis wrote in post #1155317: But adding the two together must (I am guessing here) cause them to both be evaluated as arrays before the addition can succeed. I don't think this is the case. As I said, I also logged the object AFTER adding them together, and it still is a Dict::ActiveRecord_Relation. The conversion into an Array must come after that, and this means it must happen inside paginate(). Is it possible that you are getting this: [ ActiveRecord_Relation, ActiveRecord_AssociationRelation ] No, because I printed .class.to_s to the object after catenation, and if it would be an array of whatever content, this would have printed Array, but it printed Dict::ActiveRecord_Relation. That's why I conclude that the conversion to an Array must happen within the paginate method itself. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/e46be0444635568adf2b85379baa71bc%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: password validation triggered even I update non-password attribute
Matt Jones wrote in post #1154197: On Saturday, 2 August 2014 11:41:46 UTC-4, Ruby-Forum.com User wrote: method. because I often have the case that I will update only some of the attributes. I wonder *why* validates looks at attributes which are not part of the update. Is there a use case where this makes sense? This is usually the desired behavior, because you want to ensure that the *whole* record is valid before saving. Well, I am reading the record from the database, and only update some fields, so I thought the remaining fields should be treated as consistent. :password is a outlier here, since it isn't persisted to the database. Maybe this is the reason why the problem shows up here. I thought that the record already has the password_digest, so it would be fine. :-( In your case, I might add something like: validates :password, length: { minimum: 6 }, on: :create Since (unless users can change their passwords) you only need to check it when creating a new record. That's exactly the problem: The user should be able to change the password, but if he only changes one of the other fields, he should not need to supply the password (since he is already logged in anyway). I implemented this by providing an entry form with empty password (and empty password confirmation). From the response, I remove both password fields from the params hash, if both are empty, and I also remove the user id, if it has not changed (because there is an index on it, and I don't want to trigger unnecessary index update operations). After this, I pass the params to update_attributes. When it comes to updating profile information, I had expected that this would be the normal way to do it. Am I wrong in this respect? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/24e57d34eebc453475efe3d34e080124%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: password validation triggered even I update non-password attribute
Jason Fb wrote in post #1154202: validates :password, if: lambda { self.registration_state == registered } This is an interesting idea. In my case, user attributes change after creation only if the user updates his profile, or when he clicks on the forgot my password link and I have to create a new password for him. I could therefore create a flag password_validation_required, which is true by default, but can be switched off on demand (because my application knows the cases, where validation is not necessary). The question is: Would you consider a good idea to automatically switch on password validation inside the lambda expression? I.e. lambda { t=self.password_validation_required self.password_validation_required=true t } or can this potentially lead to problems later on? Finally, a syntax question: You are writing lambda { } I would have written - { ... } Are both notations exactly the same? Also, read this book: Thank you for the recommendation! Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/ff8bb87a8d14fcb6cd7b9c586e3a8928%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: password validation triggered even I update non-password attribute
Eric Saupe wrote in post #1154001: First change the validates to only validate if a password is being passed. validates :password, length: { minimum: 6 }, :if = :password Second, remove the parameters for password if the are blank on your update method. if params[:password].blank? params.delete(:password) end The latter I only did, because in this case it would obviously not work, but I was not aware of the trick for the validates function! I think I'll have to do this for all 'validates' in my application, because I often have the case that I will update only some of the attributes. I wonder *why* validates looks at attributes which are not part of the update. Is there a use case where this makes sense? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/62ac93e1bed2c51db7a17588e03a%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] password validation triggered even I update non-password attribute
I have a User model: create_table users, force: true do |t| t.string name t.string email t.datetime created_at t.datetime updated_at t.string password_digest end add_index users, [name], name: index_users_on_name Then, I have the following validation: class User ActiveRecord::Base has_secure_password validates :password, length: {minimum: 4} end Then, I update in my controller the name and email of a certain user: ... logger.debug(' new_values after: '+new_values.inspect) if @user.update_attributes(new_values) logger.debug('+ SUCCESS') ... end (new_values is of type ActionController::Parameters) My log shows new_values after: {name=, email=} However, the update_attributes fails, and the error message says: Password is too short (minimum is 4 characters) What I don't understand is, that I don't supply a new password. Why, then, is password validation triggered here? And how should I implement this? Background for this question: This code is executed only, when a user wants to edit his profile data (which, for the time being, consist only of name and email). It is ensured that only a logged in user can execute this code, and only for his own data. Therefore, I don't require to enter the password. He had entered it anyway when logging in. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/fd05f515f4de339941398f1edba11c56%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: (Occasionally) display DateTime as local time
Scott Ribe wrote in post #1153641: And if you don't want to change the RoR default, you can think up your own name and add your own setting to the config. No, the Rails default is fine. I'll go with the solution proposed by Colin. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b8e866d09c5fdde9908d052be00c36ec%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] (Occasionally) display DateTime as local time
I store my dates in the database as 'datetime', and I use i.e. DateTime.now for getting the current date and time and doing time arithmetic. I have set neither config.time_zone nor a default locale in config/application.rb When outputting such a time value, I just convert it to string, i.e. #{my_timestamp}, which gives me the UTC time like this: 2014-07-27 11:41:50 UTC This is exactly what I want to have. There are, however, cases (for debugging output), where I would like to print for conveniece the local time for such a timestamp, in addition to the UTC time. local time means in this case the time as defined as local on the host where the Rails server (WEBrick) is running. Note that the shell, from where I start the server, does NOT have the environment variable TZ set. Now my question: From the viewpoint of Rails, does the term local time make any sense (given that I have neither TZ nor config.time_zone)? If yes, how can I format the DateTime object in a way that it shows the time in local time? If not, what would be the best approach in this case? I've already looked at the DateTime member functions to see, whether there is something like getlocal or localtime, but there doesn't seem to be one. to_formatted_s looked promising, but I didn't find anysthing in the possible time format specifiers which would help me here. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/76141a76b98eea31545c578c11ff371b%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: ActiveRecord: moving all children to a new parent
Ah, I have set it to :destroy! But why do I get the error when I assign to pto.children? I would expect such an error then when pfrom is deleted. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/fd1b8bea149268b8889927c44922a7b1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: ActiveRecord: moving all children to a new parent
Matt Jones wrote in post #1152815: On Friday, 18 July 2014 02:24:59 UTC-4, Ruby-Forum.com User wrote: saved_children = pfrom.children.to_a pfrom.children = [] pto.children = pto.children + saved_children. I finally found the time to rewrite this part of my application according to this suggestion, but I now get an error can't modify frozen Hash, when I try to add the saved children. The actual code which I am using is here: # tempdict is pfrom and targetdict is pto targetdict=Dict.find_by_id() # creating and saving a tempdict together with several children, i.e. cards tempdict=Dict.new() tempdict.save! # Code for creating and adding the children omitted for brevity cards_to_add=tempdict.cards.to_a tempdict.cards=[] targetdict.cards += cards_to_add I find it strange that I get the error on the last line. The error message is usually an indication that I am trying to save something which has been deleted already, but in this case, no deletion had been done on 'targetdict' before. Any idea, where this error could come from? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1b6e74ac6dd6b8c23b694a41297645e4%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: ActiveRecord: moving all children to a new parent
Walter Davis wrote in post #1152668: On Jul 17, 2014, at 7:27 AM, Ronald Fischer wrote: pfrom = Parent.find_by_id(from_id) children formerly belonging to pfrom, and iterating over pfrom shows the case? How then would I correctly implement the move. Reload the parent that you wish to destroy before you destroy it. I was not aware of the reload method! Thank you for pointing this out. So this would be pfrom.reload.destroy Also, maybe it would be enough to set the dead parent's children array to []. Interesting idea. I think, 'reload' is nicer, because it is more likely that this part of the interface won't change when a new version of Rails is coming. Changing the children-array looks a bit like a hack to me (we need to know that they are stored in an array). But still I'm curious: How do I explicitly manipulate the childrens array? I didn't find a suitable method in the Active Record docs, and I don't expect that something like pfrom.children=[] would do it. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b19eeaa90a77d407d99ced99f90e1372%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Upload UTF-8 encoded textfile
I think, the idea of first reading the lines, and then use force_encoding on the strings, would not work for two reasons: 1. As I have experienced, I already get the exception on the first byte which has the high-bit set (i.e. is not 7-bit ASCII) 2. If a UTF8 encoded character contained 0x0d or 0x0a, reading the line without being aware of the encoding, would split the character into two parts. In addition, this solution would not account for a BOM (unless I write special logic to extract an optional BOM on the first line being read). Although I have only files without BOM at the moment, it is likely that sooner or later I will also have to support uploading of files which contain a BOM. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/35dbf02bb1ed24e8c9bd25250ed049c4%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: ActiveRecord: moving all children to a new parent
I am stunned! Every day I like Rails more Thanks a lot! Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/bf52dae6dbe19704baae638f49c2f08a%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Upload UTF-8 encoded textfile
As far I understand this article, this related to Rails 3 and MySQL, and how to use UTF8 encoded data everywhere. I don't know about MySQL, but Rails 4 and Ruby 2 with SQLite don't suffer this problem: I didn't have any trouble, processing all kinds of Unicode characters with my application, and processing the uploaded file also works fine, as long I use my (not very elegant) trick to open it a second time with the desired encoding. It now occurs to me, that the question is maybe not Rails-specific, but a general Ruby question - how to change the encoding of a Tempfile object. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1b0696cbf4c499f52bc8de13cd7c3b3d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] ActiveRecord: moving all children to a new parent
I have a models Parent and Child, an the following association: Parent has_many :children, dependent: :destroy Child belongs_to :parent Further, I have two Parent instances: pfrom = Parent.find_by_id(from_id) pto = Parent.find_by_id(to_id) My goal is to transfer all children from pto to pfrom, and then delete pto. The first part seems to be easy: pfrom.children.each { |ch| ch.update_attributes!(parent_id: pto.id } If I run *only* this code, I can see that pto indeed contains now the children formerly belonging to pfrom, and iterating over pfrom shows that there are no children. HOWEVER, if I add the following line: pfrom.destroy I can see (from the SQL statements which are issued by this call), that all the former pfrom children are deleted! It somehow seems as if this information has been cached. Could this be the case? How then would I correctly implement the move. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f24f6034906a184a40a102fa92a2dc22%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Upload UTF-8 encoded textfile
Colin Law wrote in post #1152686: On 17 July 2014 15:42, Eric Saupe ericsa...@gmail.com wrote: That shows how to create a Tempfile with a given encoding but the question is when a user uploads a file through a form and Rails creates a Tempfile is there a way to indicate that it should always create those Tempfiles with a default encoding such as UTF-8? In that case it *is* a Rails specific issue, not a Ruby question as suggested by the OP. Indeed, you are right so far that it *might* be a Rails question. Still, I wonder why (in general) it is not possible to change the encoding of an existing (already open) Tempfile. Assuming that it is OK to rewind the file, I don't see a technical reason, why this is not possible. I don't think it would be a good idea to configure this on the Rails side. Image the following scenario: We have a website, which allows users to upload textfiles, the content of which will eventually go into the database. Since we are generous about the encoding, we also provide the user with a dropdown list to choose a suitable encoding. When the user clicks the upload button, the controller gets the uploaded file plus information about the encoding. Clearly, Rails can not anticipate the encoding of the file. It just can upload the file (binary), and provide the controller with an open file handle. Now Ruby *does* have the set_encoding method for File, and Tempfile is-a file, and set_encoding *can* be called - it just fails. We have nearly everything in place. Now, if we can find out WHY set_encoding fails (and this might be a generic Ruby question), we can find out what Rails (or the programmer) can do to let things go smoothly Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/4cf778a5a83ac07451bfc97d5fe0bb00%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Upload UTF-8 encoded textfile
Yes, it is, as I found by trial-and-error. Note that the object is not just a File, it is of class Tempfile. I think this is quite common when working with a Tempfile object. To make a Tempfile threadsafe, you have to combine the creation of the filename and the creation of the file into one call (otherwise you have a race condition if another process tries to create a tempfile in the same directory and by accident comes up with the same name). While I didn't dive into the source code to see, how Rails is implemented in this respect, it would be reasonable to assume, that for the upload, a Tempfile object is created for read+write, the uploaded file is written to it, and the file pointer is repositioned at the beginning of the file, before it is handed over to the controller. Since the uploading process can't know anything about the encoding, the file must have been opened as a binary file. That's why I had the idea that I just need to set the encoding to the desired value before starting to read from the file. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/bec1374f9fb66b2a472f3d96c3252228%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Upload UTF-8 encoded textfile
In this case, it is pretty certain that ever file will contain UTF-8 characters, and in general, I think the cases are few where we can assume input to be represented by 7-bit-ASCII. What I do not know for sure is whether or not the file will have a BOM, but I think Ruby can figure this out automatically, when supplying the BOM option on opening. It would make sense to allow also file using different encoding, such as UTF-16, but this is something I will have to deal with later. The stackoverflow link you presented, doesn't really answer my problem though. It just describes how I can *open* an UTF-8 file, and this is the workaround I'm using meanwhile (as outlined in my posting where I say: I could create a File object by opening. What I would like to know is, whether there is a simpler way (since the file, after all, is already opened when my controller is entered), and in particular why set_encoding doesn't work for my Tempfile object, even though this would work well for a File object. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/9769bdc12274b38b2bd0f8cd478c4f5c%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Validation in a 3-level association
I think that the relationships in my model are OK so far. In my concrete case, an instance of A would be a so-called (domain-specific) user dictionaries. An instance of B would be a dictionary entry (each dictionary has many entries). A C would be a so called idiom description, i.e. explaining the associated B object in different ways. Hence, each entry would contain several idioms. The idiom description has among their columns are two fields which are called representation and kind. In theory, the catenated key of representation and kind must be unique within a dictionary (different dictionaries may have the same [representation,kind] pair though). For the discussion of this posting, I didn't mention the presence of the kind column, since it just complicates the fact, and is not really important here for various reasons. I could add to C a foreign key to A, and then express my validation with the help of this key, but it seems to me pointless to introduce a new column only for this purpose. I am aware that I could do a custom validation, but I thought that the case my case is commonplace, that Rails maybe has some built-in feature for this which I just am not aware of. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/5b8fee138a78d205d25ccfe8950bf8a3%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Upload UTF-8 encoded textfile
My Rails application (Rails 4.1, Ruby 2.1.1) offers the user to upload a file. This file will then be parsed by the application, and after the parsing is done, it is deleted from the upload area. So far, I have the following: In my upload form, I have %= file_field_tag :upload, {accept: 'text/plain', class: 'file_upload'} % In my controller, params[:upload] contains an object of class Tempfile, which is already opened for reading. I am using #readline to read through this file. The problem now is that the file has encoding utf-8, and as soon as reading contains a character which isn't also a 7-Bit ASCII character, I get an exception. What is the best way to read an uploaded UTF-8 file? I was already thinking along the following line: The Tempfile class also has a method #path, which returns the path of the uploaded file. I could create a File object by opening this path, specify utf8 when opening it, and read from this. However, since this problem must occur quite frequently, I wonder whether there is a way (maybe in the file_field_tag) to tell Rails that the Tempfile object should be opened as utf8 for reading. Is this possible, or is there another good way to deal with this problem? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/fbbd55b2ea283afff4e24ccf9d2b%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Validation in a 3-level association
I have 3 models, say A, B and C, and they are set up like this: A: has_many :Bs has_many :Cs, through: B B: belongs_to A: has_many :Cs C: belongs_to B: In my model for C, I want to declare, that a column ccol within C must be unique, but only within the scope of a certain A. If the constraint would require uniqueness within a certain B, I could write validates :ccol, uniqueness: { scope: :B_id } But since C doesn't contain an A_id as foreign key, I can not express it in this way. Is there a possibility to achieve this? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1c92cfe04af45f69073d2ead29cb3d22%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Heroku vs. local WEBrick: How could be this error be undetected?
It's 2.1.1p76 in both cases. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/aea8bab4984aeaac2e3e023ec99ba89b%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: counting the result of a join (SOLVED)
The solution is found here: http://stackoverflow.com/questions/24607428/rubyonrails-counting-the-result-of-a-join Basically, I need to specify in my :dicts model, that there is an association to :cards # in class Dict: has_many :idioms, through: :cards After this, I can do: idioms.where(kind: kind).exists? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/ec99a75a5db0a6aba69f649ffbf01bba%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Changing display text of submit button without changing value passed to controller
Thanks for the suggestion. I had not expected, that there is no *simple* solution for the problem, since it seems to me such an obvious issue. If I do it with JavaScript, wouldn't the following strategy be simpler? - I set up a hidden text field and a hidden button inside the form. - My two (visible) buttons don't belong to the form, but have a JavaScript function attached. - Hence, the form has only one submit button, not two (and this button is not visible) - When the user clicks on one of the visible buttons, the Javascript function places some value (according to which button has been clicked) into the hidden text field, and calls form.submit() - My controller doesn't do a check on the button, but on the hidden textfield, to determine which button has been clicked. What do you think about this way of doing it? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/9c08c86b651554d4fdf419f4a1aebb6a%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Changing display text of submit button without changing value passed to controller
That would probably work just as well. The issue here is that you are switching on an internationalized value. No, that's exactly not the case. The switching is done based on the value of the hidden field. The JavaScript function called from clicking the internationalized buttons places some code into this field (say, 0 for reject and 1 for accept) and then calls form.submit(). My controller only checks for the 0 or 1, and is never aware of the actualy value of the buttons. Actually, the controller doesn't need to check any button in this solution. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/bd4900407a0a08dda6a5cea3bb4f5cd3%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Changing display text of submit button without changing value passed to controller
It occurs to me now that you could solve this another way, too. Simply give the two buttons different names, and test for the presence of the name, not its value. I thought of this too (and actually used this solution in a related project, just to verify that it works). I didn't like it so much from a viewpoint of style, if we check for presence of the keys instead of the value of a field. Of course, this is a matter of taste, and at least it is much simpler to understand on the HTML side, compared to having two extra hidden fields. I think there is no solution which I would *really* find satisfying, so maybe I will just go for the one which is least ugly. :-D Thank you a lot for providing such an elaborate example Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/c7dbbefee879db897a79b30b0d86b1b1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Heroku vs. local WEBrick: How could be this error be undetected?
I had the interesting case, where my application worked find locally (using WEBrick), but the version deployed to Heroku crashed. It was a syntax error, in a very short controller file, and I could easily verify, that my version and the one at Heroku was identical. What struck me, was the kind of error: In my class, I used by mistake private: instead of private (note the colon at the end) - perhaps I was thinking too much C++ recently - but I don't understand why I didn't get this error locally as well! I therefore restarte the local server and verified that it worked, and then pushed the files to heroku, to make sure that they are REALLY the same everywhere, and still, only at Heroku I got the error message. I then fixed it locally, pushed it again, and now it works everywhere. This is creepy: How can it be, that such a serious error gets unnoticed on my local system? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/3a6c4b563dfa954274727ac170cf8984%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Can I do %=.% interpolation without getting a p tag?
I have in my erb file something like this: %= simple_format(...) % The generated code is wrapped within p/p. In my case, I need the code be interpolated without this wrapping. Can this be done? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d57a3149f8a9e5c413b84db959c5e6f4%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Can I do %=.% interpolation without getting a p tag?
If you just want to print out the bare text, you can just put that in your erb tag: %= my_variable % This didn't work either, because the value of my_variable contains simple quotes, and these had been replaced by an HTML entity denotation (in this case, it is #39;). That's why I thought I would need simple_format (I was not aware that the p was coming from simple_format I should have known this) Maybe I post here my code in question: % js_unhide_idstrings=@sequence[1..-1].map {|n| 'tu_idiom_#{n}'} % script ... var unhide_ids=[%= js_unhide_idstrings.join(',') %]; ... /script If @sequence is, say [4,1,9], the generated JavaScript code would be var unhide_ids=[#39;tu_idiom_1#39;,#39;tu_idiom_9#39;]; -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/9ba5efd6a29b4a24bb6fcc6b15bf30b1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Can I do %=.% interpolation without getting a p tag?
Thanks a lot, this is the solution I was looking for! -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/e1716ce372eb86527de26943337b02b1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Changing display text of submit button without changing value passed to controller
Please have a look at this form: %= form_for @data, url: data_path do |f| % ... %= f.submit(accept, name:judgement) % %= f.submit(reject, name:judgement) % % end % These buttons display accept and reject. Clicking on the first button would pass judgement = accept to the application. This is exactly what I want, but I want to be able to change the text which is visible on the button (for example, when displaying the page in a different language). Can this be done? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/5e24e429be3356cc4cda3e666fc7fac2%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Messages Binary data inserted for `string`, but encoding looks OK to me
This is an excerpt from a rails console session: 2.1.1 :011 x=User.new({name: 'x', email: 'x...@example.org', password: '', password_confirmation: ''}) = #User id: nil, name: x, email: x...@example.org, created_at: nil, updated_at: nil, password_digest: $2a$10$sOP18GHU/e4Q.yTT.6tTguLeqR4vN1QCXTZU6mMxERO..., remember_token: nil, admin: false 2.1.1 :012 x.save (0.2ms) begin transaction Binary data inserted for `string` type on column `name` User Exists (12.9ms) SELECT 1 AS one FROM users WHERE users.name = 'x' LIMIT 1 Binary data inserted for `string` type on column `email` User Exists (0.5ms) SELECT 1 AS one FROM users WHERE LOWER(users.email) = LOWER('x...@example.org') LIMIT 1 Binary data inserted for `string` type on column `email` Binary data inserted for `string` type on column `name` Binary data inserted for `string` type on column `password_digest` SQL (30.4ms) INSERT INTO users (created_at, email, name, password_digest, remember_token, updated_at) VALUES (?, ?, ?, ?, ?, ?) [[created_at, 2014-07-06 09:45:54.350309], [email, x...@example.org], [name, x], [password_digest, $2a$10$sOP18GHU/e4Q.yTT.6tTguLeqR4vN1QCXTZU6mMxEROS.YKWJ/5gq], [remember_token, 182afad1b65b10a7aa6f9869e811e6671f0d32c8], [updated_at, 2014-07-06 09:45:54.350309]] (12.3ms) commit transaction = true We can see that everything works, and indeed, x.errors shows an empty message list. However, I wonder what the warnings (?) Binary data inserted mean. When I google this subject, the usual explanation is an encoding issue. In my case, the data contain just 8 bit ASCII, as we can see here: 2.1.1 :014 x.name.encoding = #Encoding:ASCII-8BIT I probably don't have to worry about these messages, as my user is created, but I would like to know out of curiosity -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b95345b6a72a557a92db9bde462e471d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Active Record sorting using Ruby sort function
I have a query of the form result=Parent.includes(:children).references(:children).where('') and I would like to have the result sorted in a particular way. The comparision function for the sort is complex and can't be expressed by simply ordering ascendingly or descendingly on the fields, but depends on a complex term based on fields from both :parents and :children. I currently use the following approach: ordered_result=result.to_a.sort { |a,b| my_sort_function(a,b) } I am aware that this means that all the records have to be present in memory. If there is an easy way to avoid this, it would be nice, but since I can ensure (from the context of the application), that the number of records returned from the query is always smaller than a certain, system-wide constant (currently 250), this is not a real problem. However, I wonder whether my approach to convert the ActiveRecord::Relation to an array is a good idea. Maybe there is a better way to implement sorting? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/6a3b981e64a12f0efa8e25cfe5dc4c97%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: nokogiri missing libiconv error. Chapter 3 of RoR book tutorial
Could it be that you are running OSX 10.6? I have the same problem, and already contacted the nokogiri supporters. At least on *this* OSX version. it doesn't work. I have also informed Michael Hartl to consider this in the next update of his tutorial. You will have to do without Capybara. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/8e4c03c6cb08def2c878589e32b9cc45%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] counting the result of a join
I have in my model :dicts, :cards and :idioms. Each Dict has many Cards and each Cards has many Idioms. Also, :idioms has an Integer column :kind. I would like to find out, whether a certain dict object has at least one Card which has at least one Idiom where :kind has a certain value. This is my (working) code: def has_kind?(dict,kind) Card. joins(:idioms). where(dict_id=#{dict.id} and cards.id=idioms.card_id and kind=#{kind}). count 0 end This works, but can it be done better? I also tried to omit at least one of the id comparision by doing something like: dict.cards.where(cards.id = ...).count 0 but this doesn't work (count is not applicable in this case). -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d91bf7a05f29d5fb78cef7d4d6ea0f0d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Active Record: Eager Loading (syntax question)
Let's have model :parents and :children, where one parent can have many children, and that I want to do something like this: plist=Parent.joins(:children).select('*').where(parents.id=children.parent_id and children.cfield=#{...}) plist.each { |p| do_something_with(p,p.children) } Now I learned from http://guides.rubyonrails.org/active_record_querying.html , that this is inefficient, due to the SELECT statements generated inside the block, and that I should do eager loading instead. From my understanding of the tutorial, I should replace 'joins' by 'includes': plist=Parent.includes(:children).select('*').where(parents.id=children.parent_id and children.cfield=#{...}) However, this raises the exception that there would be no column children.cfield. It seems that with 'includes', we can only query based on values of the Parent table. Is this correct? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f814f36645d4f47a87ebf77a0a8d3194%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] What is a good practice for storing additional classes
My Rails application also contains classes which are independent from the Rails framework, in that they could be reused unchanged if I would, for example, created a non-web-based, command-line version of my app. Such a class could be one which implements business logic, or a simple utility class. The question is: What is a good practice of integrating it? In a non-Rails application, I would create a directory app/lib and put the rb files there. I would ensure, that RUBYLIB points to this directory, and I would do a require in those files where the classes are needed. This should also work within Rails. However, is this good practice? How are experienced Rails developers handle this? Note also, that these classes will be instantiated only inside a controller, not in a view or model. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/852ced0ac40d6daa71fcd39d6e62cbd2%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: What is a good practice for storing additional classes
Robert Walker wrote in post #1150810: Ruby has a mechanism for this. They are called gems, libraries of shared code. So you are suggesting to write a gem for this? I would have not expected this suggestion, but I will think about it. Rails provides a lib directory for code more tightly coupled with the application in which they are used. I have noticed the lib directory, but I was a bit reluctant to use it, because - if I understand it right - whenever I change something in a file below lib, I would have to restart the rails server, which is inconvenient during development. If you do have model classes that are not subclasses of ActiveRecord there's still no reason they can't live inside the models directory along side your ActiveRecord subclasses. Shouldn't there (in models) be only classes related to - well - modelling, i.e. related to a data model? For example, if I have a class which represents a connection to separate processes (say, a proxy to a Clearcase server), this wouldn't fit well to the other stuff in the model directory. Ruby also provides modules and mix-ins for adding functionality to existing classes, this can often be a good way to implement utility methods. I guess you mean the files in helpers? Yes, this one I use already for various utility functions, but helpers usually are targeted for views (I *can* make them available in controllers, but they still would be available in views too). I see that there are several ways to do it. Could you also explain, why my naive approach (to create a separate lib subdirectory below app and put everything there) would be a bad idea? I have never seen someone suggesting this, so I suspect it must have a drawback which I just don't see yet. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/6109d0086f967b0382558a82a4985809%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Button invokes update instead of index
Does this mean that I can't solve this with a *button*, but would have to use a *link* instead? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b7071f13fb2a2efa9fcd84a80eb3ffb6%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Button invokes update instead of index
Walter Davis wrote in post #1150186: On Jun 19, 2014, at 2:09 AM, Ronald Fischer wrote: Does this mean that I can't solve this with a *button*, but would have to use a *link* instead? It's important to note that you may style a link to look like anything -- even a button. But you cannot remove the button-ness from an actual button and have it do anything besides submit the form containing it. I see. Maybe I'm using the wrong design here in the first place. Here is what I am going to do: The user arrives the web page in question, from an overview page. The overview page gives a list of all instances (in this case, of type Card), by listing only the primary key of the instance. When the user clicks on one of those keys, s/he arrives at a page displaying all the data for this Card instance. At this point, I will give the user three choices: - delete the Card - edit the Card - show again the list of all cards My (probably stupid) idea was to write a form without input fields, showing only the information on the cards, and having 3 buttons for DELETE, EDIT and LIST. Now I understand that a submit button in a form helper for a form_for, which has as argument an existing object, automatically calls the update function. Thinking about it, this makes sense, and I now think that I was misusing the form_for(). Maybe I should just output the data without using a form at all, and use button_to() if I want the clickable part look or behave like buttons, or use links and style them as buttons, as you pointed out. In any case, using a form in my particular case, doesn't make much sense. Would you agree on that? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/a1e40d17786e980f2fba3705ab8aade8%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: finding associations in sorted order
Thanks to all contributors! Hassan Schroeder's sharp eye finally spotted the culprit. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/6645d470cd8bafd851eca4a3dc1b4164%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Button invokes update instead of index
I have nested resources resources :dicts do resources :cards end and in my form form_for [@dict,@card] do |f| I have the following button: %= f.submit('LIST ALL', url: dict_cards_path(@dict.id), class:'kanren_button', name:'list_all', method: :get) % The generated HTML code is: input class=kanren_button method=get name=back_to_list type=submit url=/dicts/6/cards value=BACK TO LIST / I would expect that clicking this button would call Card.index, but I get instead the error message The action 'update' could not be found for CardsController It is correct that I don't have a CardsController.update yet, but I don't think I should need one at this point. The output from 'rake routes|grep card' looks fine for me: dict_cards GET/dicts/:dict_id/cards(.:format) cards#index POST /dicts/:dict_id/cards(.:format) cards#create new_dict_card GET/dicts/:dict_id/cards/new(.:format) cards#new edit_dict_card GET/dicts/:dict_id/cards/:id/edit(.:format) cards#edit dict_card GET/dicts/:dict_id/cards/:id(.:format) cards#show PATCH /dicts/:dict_id/cards/:id(.:format) cards#update PUT/dicts/:dict_id/cards/:id(.:format) cards#update DELETE /dicts/:dict_id/cards/:id(.:format) cards#destroy What did I do wrong? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d957c99d19bdc337e80d01dd930cf9e9%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: CSS Load Order Headache
Jason Fb wrote in post #1150056: Also you didn't show us the actual styles themselves, and I'm not sure how familiar with CSS you are. In case you aren't (no offense intended-- I am writing this to be thorough), the style inside of scaffold may be more specific than your own style. Actually, this was not the case. I used Google Chrome's inspect element feature, which is very handy, because it shows not only the definition place of the styles, which apply, but also, which other styles have the same (or lower) specifity (and where their definitions are). In effect, changing the load order solved the problem. Alternatively, take the styles in scaffold and move them to your app (cut paste), and then delete the scaffold file. Unless it's a library, treat it as boiler-place starter CSS, not as a library you want to maintain congruence with. Thanks for the suggestion! I will consider this do for future conflicts. If we were talking about some library's CSS, on the other hand -- like Bootstrap --- then I would not recommend you edit the library's CSS directly. Thanks for this warning too! While I don't feel so comfortable with Bootstrap, I am currently looking for other libraries and will probably face this problem again. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1b96d134ead9c44b721f44352b8bf9e5%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: DB query: Finding only the id values
Jason Fb wrote in post #1150058: However, as you are considering writing raw SQL, keep in mind the danger of SQL injection. Beyond the reason stated to keep your SQL database-independant (which is strange advice IMO since it is very rare to move between data stores on a large project, Not so rare. For example, I do the development with SQLite, but the production is on Heroku and uses Postgres, and customers might want to use MySql. and even if you do it is pretty easy to re-write SQL), the most important thing here is that you don't a security vulnerability for SQL injection. Oh, you are absolutely right. I see the danger. These are the times where I'm missing Perl's concept of tainted strings... Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1ae514b05a2105595d87d403a9bd60b8%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: DB query: Finding only the id values
Jason Fb wrote in post #1150062: It took me several years of working with Rails to understand this nuance, and I believe it is poorly documented in the AR guide. reading the source may be a good idea for some, but remember the Rails source isn't easy for everyone to read (although a good idea!). I don't mind so much *reading* the source then relying on the information we get from it. Even if you see that something is implemented in a particular way, you don't know whether it is just incidentally (and in the next minor release will be implemented differently), or whether it is an undocumented feature (which might or might not make it in the API), or whether it is really part of the official interface. If something is specified in the API, there is at least good hope that we don't run into incompatibilities (although when looking at the evolution of Rails, this principle seems to have been violated occasionally). Since it is so important to how AR works, I think this facet of AR should be documented better in the AR guide (specifically, that the AR methods return ActiveRelation objects which don't actually fetch anything until you want to look at them). It's a brilliant implementation pattern, but counter-intuitive to newbies. It's just lazy evaluation at work, and as such not so much counter-intuitive. It's only that it is not obvious that the design choice was done in this way... Ronald -Jason -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/0c92246ba34e7b082c0b59e339d67c51%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: DB query: Finding only the id values
Walter Davis wrote in post #1150083: You say tainted, and I hear Soft Cell... This too, of course ;-) Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b269a33119d682e90627e19bea8a33ce%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] finding associations in sorted order
I have in my model class Card ActiveRecord::Base has_many :idioms,dependent: :destroy end class Idiom ActiveRecord::Base belongs_to :card end In my schema, Idiom has an integer column kind. Given a certain card, I would like to have all associated idioms, but sorted in descending order according to the 'kind' column. I could do a @card.idioms.sort { } but would prefer doing the sorting by the time the data is retrieved from the database. I googled two suggestions: (1) @card.idioms(:order = 'kind DESC') This doesn't seem to have any effect. (2) @card.idioms.all(:order = 'kind DESC') This gives the error wrong number of arguments (1 for 0). I think I could do a Idiom.where() and put an order restriction there, but I feel that Rails must have a way to specify sorting when following associations, and maybe I just made some silly mistake. Any ideas? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/24d5871e8a39c5a3963122c9dffeeefc%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: finding associations in sorted order
Walter Davis wrote in post #1149912: On Jun 17, 2014, at 8:34 AM, Ronald Fischer wrote: It sounds to me as though maybe all of your idioms have the same value (or null) in their kind column. No, they have correct values (1, 2 and 3). Actually, the logic of the application ensures that there are only those values (I should this place into the model too). Does it mean that in your opinion, my attempt to sort them would be correct? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d8dad43e8c45f6895da580a710bdf0f7%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: finding associations in sorted order
Colin Law wrote in post #1149914: On 17 June 2014 13:34, Ronald Fischer li...@ruby-forum.com wrote: In my schema, Idiom has an integer column kind. Given a certain card, I (1) @card.idioms(:order = 'kind DESC') This doesn't seem to have any effect. What do you mean by not having any effect? It means that they always come out in the same order (which, accidentally, is *ascending* according to the kind values, which is likely a consequence, that I create the Idiom objects with ascending kind values, and so the probability is high that - with my small development database - I just get them back in the order they were created. BTW, I looked at the result by running .inspect on the returned data, and from this I found that it's not sorted descendingly. If you have a look in log/development.log you will see the query being run and check that it looks ok. Oh, of course, I should have thought of this myself! I'll do that next time I'm on the development host! Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d6524f4222847441bb2c4a4b149829e4%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: finding associations in sorted order
Hassan Schroeder wrote in post #1149926: ?? Not, the OP originally posted: @card.idioms(:order = 'kind DESC') which is 1) not equivalent, and 2) won't work. Oops I think that's it! Will check it on the next occasion. (The OP is herewith ashamed) Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/af4d34b85ace1d27bd8f12abc19f8767%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: CSS Load Order Headache
Thanks a lot for the helpful answers! Both solutions make sense to me. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/1618fa77bf17eda1525e9099be90cc29%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] DB query: Finding only the id values
My solution works, but I wonder if there is a better one. I have a model (:cards), which has a foreign key :box_id. I am interested in the id's of those cards which have a certain box_id. Currently I assume that I can easily hold an array of all thos :cards in memory (i.e. no cursor needed). This is my current solution: Card.where(box_id: params[:box_id]).map {|c| c.id }.each do |cid| # Do something with cid end This is compact, but I don't like the fact that first, all data from the retrieved Card objects needs to be stored in memory at least temporarily (there is even a 'text' field in Card!), but only the id is needed. I thought as an alternative to use find_by_sql, but the API documentation warns that this should be only used as a last resort, because it makes us dependent on the syntax for a particular database. Although in my case, the SQL query would be so simple that I don't fear I would run into compatibility problems when exchanging one database for another, I wonder whether there is a simpler solution, using just ActiveRecord functions. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/05a79fc3b1b9e3ea9a0c7b650c5b5e81%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: DB query: Finding only the id values
Colin Law wrote in post #1149753: On 15 June 2014 09:29, Ronald Fischer li...@ruby-forum.com wrote: Assuming that you have the relationships setup accordingly (so card belongs_to box and box has_many cards or something similar) Actually I have both (belongs_to in :cards and has_many :cards in box); would it be sufficient to have only one? then to get the cards belonging to a certain box you can just use @cards = @box.cards then to get the id of each box in just use box.id I see. Thus, applying your suggestion to my case, it would be: Box.find_by(params[:box_id]).cards.map {|c| c.id }.each do |cid| # Do something with cid end But this solution still has the effect of having an array of all the Cards, so I don't really see an improvement over my original solution. Or did I miss something? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/7f2deb03626cbae546b1506be1d41004%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: DB query: Finding only the id values
Hassan Schroeder wrote in post #1149759: On Sun, Jun 15, 2014 at 1:29 AM, Ronald Fischer li...@ruby-forum.com wrote: (assume that ) box = Box.find(box_id) box.cards # has the cards you want *if* you need all the attributes box.cards.pluck(:id) # builds a query to fetch *only* the card ids May I ask how this works (internally)? For pluck() to be applied, Ruby has first to execute box.cards() to get an Array of the cards. Unless the Card objects are implemented as proxies, which only fetch their data from the database if one asks for it, I would at this point, at least temporarily, have all the selected Card data in memory, isn't it? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/2845a06ed41c1407411b5ac77b8318b0%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] CSS Load Order Headache
I used rails generate scaffold for part of my application, and this looks fine so far. Now I would like to change a style for the a element, which happens to be defined in scaffold.css.scss. I don't want to touch the generated file, so I place the definition into my own file. I have one (rkanren.css.scss) which has CSS definitions which are used project wide. Testing the page, I see that my style change is not honoured. Using the inspect function of Google Chrome, I indeed see that the definition in scaffold.css overrides mine (although both are specific in giving a style to, say, a:visited). Next, I tried to place my scss file explicitly in the load order, for example: *= require rkanren *= require_tree . *= require_self But to no effect. I tried the other 5 permutations of this sequence too, but Chrome always shows that my definition is masked. What did I do wrong? I am using Rails 4.1.1. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/88663120d4aacef479295b701b689812%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] SerializationTypeMismatch when retrieving (not: storing) object
I don't understand the following example from the ActiveRecord::Base section in http://api.rubyonrails.org/ : == class User ActiveRecord::Base serialize :preferences, Hash end user = User.create(preferences: %w( one two three )) User.find(user.id).preferences# raises SerializationTypeMismatch == What was the design choice, that I get the exception in the *last* line? I could understand, if there is an exception in User.create, because :preferences is supposed to be a Hash (if I understood correctly the 'serialize' function), and instead an Array is passed. But the documentation clearly says that the exception happens at retrieval: == You can also specify a class option as the second parameter that'll raise an exception if a serialized object is retrieved as a descendant of a class not in the hierarchy. == Is there a deeper reason, why this error is caught at retrieval, and not already at the time of storing the value? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/7e006639e4c9ebde871d76fe63d3b1c1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Calculating string length in a model
I'm using Ruby 2.1.1 and Rails 4.1.1, with SQLite and, respectively, Postgres. All my strings are supposed to be UTF-8 encoded. Now, assuming I create a field in my model as data:string{20} can I safely assume, that this will store up to 20 characters, even if each character happens to be 3 bytes long in UTF-8 encoding? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f8745945a4fc1581b8072e461ae0ca50%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Design question: Redirection to a create action.
Thank you so much to go through all the trouble and even lay out an example for the code. While I have meanwhile already redesigned the login logic, reading the short tutorial of Reform on github, and also your example, let's me think that I could use Reform well for another piece of my application, which is kind of a control center and is connected to several objects in my model. I think I'll give it a try at that point! -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/a3474c3d322e237b54ba46b88bc815e6%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Form helper: Linking radio button to label
Walter Davis wrote in post #1148961: Look at the generated HTML in a browser. In order for the label to affect the radio button, one of two things must be true: 1. Either the label's for attribute exactly matches the radio button's id attribute, or Got it! I now can see my mistake. The label should be %= d.label :filtertype_lefteq, 'Starts with...', value: 'lefteq' % 2. The label wraps around the button and does not have a for attribute. Just out of curiosity: How can *that* be done inside an ERB file? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f65c4a2420c35a32b3668128d54b120d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Re: Design question: Redirection to a create action.
Jesse Knutsen wrote in post #1148836: On 6/4/14, 1:19 PM, Ronald Fischer wrote: However, the form has two buttons, and one is (from the viewpoint of logic) doing a GET and the other one should do a POST. Of course I can't have both. Maybe it is the form which needs to be modified? A form can do a get or a post, but not both at the same time. You would need to change the form action though JS. also you would have to have your routes set up accordingly. I didn't think of the possibility to use JS in this case. This would be certainly a possibility, but I wonder: Would you still call it good design? Or should I design the user interface in a different way, for instance having two forms (one for the GET and one for the POST case)? The latter might be cleaner from the programmer's viewpoint, but perhaps confusing to the user. This is a problem which I still will have to solve, when abandoning the current Login design and use the login functional object you suggested, because even then, I would have a single form which, depending on the button being pressed, might to a creation of a Dict object, or a retrieval... -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/7c4f0c3bd5ea7972d991fd7e2e12052c%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Re: Design question: Redirection to a create action.
mike2r wrote in post #1148859: I do think that ajax is a good recommendation. Selecting, creating, or changing a dictionary could be accessed from any page making it much more user friendly and a success growl is fine, but again, you should be prepared to handle the case where a user tries to create a dictionary that already exists (which could be a simple error message instead of a success growl). Thank you for your elaborate answer. After having read all the recommendations, I think I will proceed in the following way: - I will clearly separate login from Dict maintenance, since the possible benefits I hoped from my original design, are small compared to the trouble it will cause in other places. - Since I have no experience with Ajax, and are even a newbie when it comes to Rails, I will first make the application as simple and straightforward as possible, not using the benefits of Ajax, even if it means that the page might be less user friendly, and after I mastered Rails fully, I will learn Ajax and do a redesign. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/585de6caafe7009b2d894cd79a0989e5%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Form helper: Linking radio button to label
My form essentially looks like this: %= form_for :xxx, url: xxxs_path, method: 'get', enforce_utf8:true do |d| % %= d.text_field('filter', value: @filter, maxlength:64, size:16) % %= d.radio_button(:filtertype, 'regexp') % %= d.label :filtertype_regexp, 'Regular Expression', value: 'regexp' % %= d.radio_button(:filtertype, 'lefteq', checked:true) % %= d.label :filtertype_lefteq, 'Starts with...', value: 'lefteq' % %= d.submit(value=FILTER LIST BELOW, name: 'filter') % % end % I thought from this association between radio buttons and label, clicking on *text* (i.e. 'Regular Expression' should already cause the button to be selected, but this is not the case. Did I miss something here? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/fb20194dc119e820ab3d7d624b52dbbb%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Design question: Redirection to a create action.
My application should behave like this: - My application manages (among others) a resource called Dicts, i.e. there is a dicts_controller, and my routes.rb contains a resources :dicts. - I have a home page (starting page), which will eventually contain some user authentification (not implemente yet), and then allow the user to manage the Dicts objects. I have a home_controller and my routes.rb contains match '/login', to: 'home#login', via: 'get' root 'home#init' and init.html.erb contains the login form. So far it's quite conventional. Now to the perhaps unusual part: - For convenience to the user, the login form contains not only fields for entering the user data (userid, password), but also an entry field for a Dicts object, and *two* submit buttons, one with the meaning of login and create a new dictionary, and the other one with the meaning login and open a existing dictionary: %= form_tag(/login,method:get, enforce_utf8:true) do % %= submit_tag(value=Create New Dictionary, class: 'kanren_button', name: 'create') % %= submit_tag(value=Open/Pick Existing Dictionary, class: 'kanren_button', name: 'open') % % end % Now the problem: My HomeController.login method checks, whether the user is authorized, and if he is, needs to go to the Dict controller and either :create a new Dict object or :show an existing one. My problem is that to :create a Dict, would require a POST action (if I want to stick with the REST model), but a redirect_to url_for(:controller = dicts,...) will always create a GET request. I was thinking of the workaround to use redirect_to url_for(:controller = :dicts, :action = :new) and inside Dicts#new use the parameters passed, to create a new Dicts object, and (if successful) redirect to Dicts#show or whatever, but this doesn't seem to be an elegant solution. Another possibility is to invoke Dicts.create from my Home.login method, but this doesn't seem to be good style either. Any suggestions on how to proceed? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/3a716898bf5663774754e11db41c90b6%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Design question: Redirection to a create action.
Jesse Knutsen wrote in post #1148805: I am not a huge fan of an approach that would need to redirect in this way. Instead, why not create a new class called login or something like that. You will need to adapt a bit to your needs, but the basics are sound and should apply nicely. I don't think this would really solve the problem: From the model, user and login data are already separated from the Dicts data (the user id is a foreign key in the Dicts mode, pointing to the user who owns the Dict). In the controller side, I have them also separated: The HomeController is responsible for the Login (I could also have named it LoginController), and the DictController is responsible for managing the Dict objects. I don't see wll how what can be improved in this area. The problem is the user interface. Clicking one button performs a login AND at the same time either CREATES or OPENS a dict object. If I would split this into two views, one for login and one for the usual interface of maintaining dictionaries, I wouldn't run into this problem, but this would be less convenient to the user. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/734d7bdc034dbe3094b14cd77314d635%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Design question: Redirection to a create action.
Walter Davis wrote in post #1148806: I would definitely not mix the login logic with the show the home page logic as you seem to have done here I fully agree that from a programmer's viewpoint it would make the problem much cleaner to solve. However, when developing software, I try to see the user's perspective, and I'm reluctant to change the user interface just because it makes my task as a programmer easier. After all, we are writing programs *for* the user, not for ourselves. I think most users would accept the approach you are suggesting (where in my case, BTW, no operation will be permitted unless being logged in), since they are kind of used to it, but this doesn't mean that we shouldn't make him the life easier. In my application, the user will *always* provide an username, and *always* provide a dictionary name, before s/he can start any sensible work, so it certainly makes sense to request both in one go, when the session is being established established. But at least I learned from the answers, that no really clean solution seems to exist for *this* kind of user interface :-( -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b764d08a5092a9d2d9b34d16973ef9e6%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Design question: Redirection to a create action.
Jesse Knutsen wrote in post #1148818: On 6/4/14, 10:30 AM, Colin Law wrote: You are 100% correct, but he was going to redirect to Dicts#new. Only as a work-around, but as I said, I was not so happy with this either. DictController ... new if params[:new_dict] create logic else new logic This would get very convoluted and inelegant. Yes, absolutely! Hence why I feel a Class of login that will do both the login logic and the create Dict logic in one place This would be what I called HomeController, isn't it? Or do you mean a separate helper class, which is *not* a controller? I thought about doing the Dict creation in HomeController.login, but then I have the logic of dealing with Dict objects twice: The larger part will be in the DictController, and the creation logic will be in HomeController. In addition, I expect in a later version HomeController *also* to be able to create Dict objects. Its similar to _http://railscasts.com/episodes/416-form-objects?view=asciicast_ I will have a look at this. Meanwhile I was thinking whether the main problem comes from a different place: A form can issue a GET or a POST, right? But the method must be specified inside the form; in my case, I have it set to GET. However, the form has two buttons, and one is (from the viewpoint of logic) doing a GET and the other one should do a POST. Of course I can't have both. Maybe it is the form which needs to be modified? If I could attach the method (GET/POST) to the submit button instead of the form itself, this would solve my problem. Maybe you could have a look at my form and let me know whether I could do this better? One other issue is that I am using the 'form_tag' method, but Rails also offer form_for. Would I get some benefit of using form_for (maybe based on a Dict object?). -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b6032cb5651ecc76c9c5041e25d34022%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: Design question: Redirection to a create action.
Jesse Knutsen wrote in post #1148812: On 6/4/14, 10:08 AM, Ronald Fischer wrote: Essentially you are calling two different actions right now (in your design) where the first leads to the second through a redirect. This redirect will actually redirect the user on the browser level, its not just a render. While you can do that, its not efficient. This method would conglomerate the two into 1: A login. If valid (valid being defined as a valid set of user credentials and valid entries for the new Dicts) it would trigger a session creation and the appropriate Dict creation, based on the button that is clicked. So, basically, my current login method would go into the Dict object? This indeed would make it easier. The reason why I had a separate controller for the login stuff was, that I thought that when my login logic gets more sophisticated (with password, authentification and all that thing), it would make more sense to have a separate controller for this. I now start to realize that I want to have the cake AND eat it. Either I should completely separate the login from the rest of the program, as for instance Walter Davies suggested above, or I want to have it together in one form, but then it means that two controllers cause trouble. Actually, I feel that I am putting too much logic into a controller. It would be cleaner to factor these things out to helper classes which can be called from everywhere. Just a thought experiment: Imagine that my design would have in the footer of every page an entry field and a button saying create a Dict, I don't think I would have to redirect to the Dict controller and then going back to the original place just for this. Instead I would have somewhere a Dict factory, which just creates, initializes (and returns) the new Dict object. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/0a7e8b544189e9fb7988986557aed87d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Help me understanding assets path
I've put my favicon into app/assets/images and include in my header %= favicon_link_tag 'my_favicon.jpg' % The favicon is correctly recognized by the browser, so it works perfectly. When viewing the source code, I see to my surprise that the following HTML code is generated: link href=/assets/my_favicon.jpg rel=shortcut icon type=image/vnd.microsoft.icon / Aside from the MIME type (I had expected that rails would generate image/jpeg), what really puzzles me is the path. The file is definitely in /assets/images, not in /assets . How can the browser locate the file? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/66e93e14a8fcfe55dee696e451f6ea17%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
Thank you for the suggestions. I went through the tutorial found on the web (which was explaining the concepts using the example of making a blog site), but could relate what I have learned, only to the concept of the idioms in my project, but not to the rest of my application. I now see that is a good idea to treat the user as its own resource, because sooner or later I will need this anyway, and I will try to redesign my application. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/24c5eb2b7daf193ca5c12a955d444071%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
mike2r wrote in post #1147433: On Wednesday, May 28, 2014 2:55:59 AM UTC-4, Ruby-Forum.com User wrote: -- Posted via http://www.ruby-forum.com/. When you get to the point where you are going to use password authentication, re-read the user authentication part of the tutorial. Thanks, I will do so. I already started to read the tutorial you recommended, and I must say it's really well written! Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/c235918d076fe2a564a28a73bad69e7d%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
You did grasp the concept of my application amazingly well, only that the only possible ways to edit a dict is to add and remove idioms (would you see this as editing the dictionary, or as manipulating the Idiom class?). The reason why I did not follow the CRUD way - and maybe this I was mislead here - was the following: When starting the design, I started with a concept of the screens the user is going to see. The initial screen will present an entry form for the name of the dictionary, the user name, buttons for creating and opening a dictionary, and - for the creation case - an entry field denoting a dictionary type (think about it as the language for the dictionary, but the concept is more general). After clicking one of the buttons, a new screen appears from where the user can click various buttons - exporting the dictionary, start one of three predefined training types, manually adding idioms to the dictionary (but on this screen no possibility of deleting or editing idioms, nor for the deletion of the dictionary). My idea was that the logic for each web page should correspond to one controller method. In this case, I have used two different controllers: For the entry page I have a login_controller (because I would like to add password authentification later on), and for the second form I have a dict_controller. Similarily, I am planning a training_controller for doing the idiom training, and another controller (maybe idiom_controller) for adding, deleting and editing individual idioms. Maybe this mapping web page to controller is, from the onset, bad design? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/c2408d1a952170480088754d28d37f13%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Finding a record which I had created
Walter Davis wrote in post #1147134: @dict = Dict.where(:dictname = dict_name).first It will either return a record, or nil. Thanks a lot. This works perfectly well! Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/d07be6b8a9d783c6a180df13f1e06999%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Finding a record which I had created
I thought this is an easy one, but: I have created a record, and later would like to retrieve it again. Here is an excerpt of my schema: create_table dicts, force: true do |t| t.string dictname ... end My model ensures that dictname is unique: validates :dictname, presence: true, length: { minimum: 3 }, format: { with: /\A\D/ }, uniqueness: true In my controller, I tried this to fetch a Dict object, when the value for the :dictname field is stored in variable dict_name: if Dict.exists?(:dictname = dict_name) logger.debug('found dictionary with name '+dict_name) dictid=Dict.where(:dictname = dict_name).select('id').first.id logger.debug('dictid='+dictid.inspect) @dict=Dict.find(dictid) However, the line to calculate dictid fails with TypeError (can't cast Hash to integer) which would suggest that the hash argument to the 'where' method is unexpected. But this can't really be, can it? So, my questions: - Why do I get this error? - How do I fix it? - The whole procedure to get at my Dict record, looks unnecessarily convoluted to me. Isn't there an easier way to do it? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/acd4904d49a136d008319f198800eef1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Finding a record which I had created
Walter Davis wrote in post #1147113: ActiveRecord already has a finder that can do all this in one line: Assuming that's the only thing needed to create or find an existing Dict, you should be all good there. No, it should not create one. If there is no suitable record, I want to display an error message to the user. Hence, find_or_create isn't suitable for me. BTW, I also tried Dict.find(:dictname = dict_name) but this too complained that there is a hash, which can't be converted to an integer. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/27a85af7e65236ed0636ef2941572b0a%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Finding a record which I had created
Thanks, I will try this! I wonder: Where do I find a specification for this feature? I guess Rails automatically generates this kind of find_by_... functions for each attribute in my model, which as uniqueness set. Where is this documented? My biggest problem with rails is getting from the API docs the information I need. Just for my understanding: Could you also please explain, why my original (complicated) version failed? Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/354085d79b1882e35595484f902a0268%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: link_to with array parameter for URL : What does it mean?
Thanks for the explanation! I noticed your response only now, and it would have at least partially answered my other question I had posted in this forum too ;-) I think I get the idea with nested routing now. What I still don't understand is a *syntactic* issue: How to map this feature to the API description. Looking at, for example, http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to I can not find a link_to with a signature which would allow for an array as the second parameter. Is this an omission from the API description (which I maybe should report to the maintainers), or did I just look at the wrong place? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/7331344edac494094c8eeaf648c68c48%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
Евгений Шурмин wrote in post #1146886: get 'dict/:id/manage', to: 'dict#manage' , as: :dict Could you please kindly explain, what the effect of the as: :dict is in this case? I understood that I need the as: parameter for those cases where I want to name the route differently, but in this case, it is always 'dict'. With other words: What would be the effect if I just leave out as: :dict? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/a54eb15ee44625f00b0a29778f740f56%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
mike2r wrote in post #1146887: I would use resources, as Scott suggests, but limit the actions that you really need such as: resources :dicts, only: [:show] Now in my case, the action has a non-standard name, i.e. :manage. Can I use this too in the only: array, or should I instead use a standard action (in this case probably edit), which then, inside my controller, invokes the manage method? From my understanding of the Rails Routing From The Outside guide, routes.rb defines which controller methods are invoked, when a certain request arrives, and the resources definition just creates standard routes with standard action names for the common case (show/index/edit/). Did I grasp this correctly? If I understood this right, I would have two possibilities: Use ab action name which reflects the purpose of the action (here: 'manage') and write a special route definition, as Евгений Шурмин suggested above, or use the standard action names, and use a 'resources' definition. From a viewpoint of maintainability, what would you consider the better solution? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b8087ed9cd649044bbdc7045d45d5058%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Re: link_to with array parameter for URL : What does it mean?
Walter Davis wrote in post #1147032: Think of the array of elements as the first variable passed to the method. You can have three or more elements in that array, if that's how deep the nesting goes. Well, this part I understand; it's just the usual parameter passing, and of course you can pass any parameter (and, actually, it is the second parameter, not the first, but this is a minor issue). But ... But the array itself is the first variable, and in that limited way of looking at this, means that the documentation is correct to a point. ... I don't quite agree. Looking at the description of the possible signatures, the documentation says: = link_to(body, url, html_options = {}) # url is a String; you can use URL helpers like # posts_path link_to(body, url_options = {}, html_options = {}) # url_options, except :method, is passed to url_for link_to(options = {}, html_options = {}) do # name end link_to(url, html_options = {}) do # name end = In our case, the first of the signatures applies for our nested routes example (because all the other ones have a hash at the second parameter), and the *description* for it says: url is a String. I thing this should be instead url is a String or an object or an Array of objects, and the objects should be a subtype of ActiveRecord::Base. Do you think this would catch it? If not, it means that I'm still lacking some point of understanding here. I agree, it would be good if there was a signature showing this in the API docs. Good thing that Rails is open source -- you can get a commit out of this if you write it up and submit a pull request on GitHub! Maybe I would better submit a correction to the docs to the email address mentioned at the bottom of the apidock.com page. I'm still pretty new in the development with Rails, as you certainly have noticed, and at this stage, fixing something - even if it is only in the docs - could do more harm than good. Ronald -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/10eb24292e5e093baaeb57938e8a727e%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Beginner's routing question: Redirecting to a different controller
Thanks a lot for the detailed explanations. Two remarks for this: As for the naming, my application evolves a dictionary of foreign language idioms, and the main purpose it to train the user in the usage of these idioms. From the perspective of the user, there are 3 types of screens (HTML pages): - The login page (where he identifies himself, chooses (or create) a dictionary) - The Management page (where he can import/export dictionaries to/from database, merge other dictionaries into the existing ones, add new idioms (this is really an edit action) and, most important of all, select one of several training plans and start trainig). - The Training page, where an idiom training is performed on the fly. This page also allows, for convenience, editing vocabulary on the fly (but only the one which is presented right now). From this setup, I found that the usual CRUD actions don't go that well with the application, and that's why I invented the action manage in dict, and in the meanwhile the action start in the (new) training_controller. However I am flexible with names, and if an experienced Rails developer strongly suggests going with standard action names, I certainly don't object. After all, I can still keep the meat of my code in my manage routine, and just have the edit method call manage(). As for generate scaffold, I have used this when doing exercises back with good old Rails 1, but now with Rails 4, the tutorial doesn't use generate scaffold anymore, but always generate model and generate controller. Do you recommend me to investigate into generate scaffold too? Thanks a lot for your detailed comment. It really helps a lot! One final question: I have read various tutorials, but when it comes to look up the API, I found the documentation a bit confusing, and difficult to find what I am looking for. You gave for example a suggestion to use the resources method with the path_names: parameter. Though I have stumbled several times over the usage of 'resources', I haven't found a single place, which would explain the usage of all parameters (such as path_names:) and examples of usage. Right now, when I really want to know how something is done in Rails, I google for it, hoping that someone else had the same problem. This often works out, but I would be more happy if I had a documentation of the Rails classes and methods, in a similar way as it is for Ruby and the standard functions and -classes. Is this available, or is Rails in the flux so much that we can't expect this yet? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f886daa904b0e83f3a47af0b52b7b01a%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] link_to with array parameter for URL : What does it mean?
(Crossposting Note: This topic has been posted already at https://railsforum.com/topic/1933-link-to-with-array-parameter-for-url-what-does-it-mean , but did not get a reply so far) I found in http://guides.rubyon...-a-partial-form the following example: link_to 'Destroy Comment', [comment.article, comment], method: :delete, data: { confirm: 'Are you sure?' } I was surprised to see an array as second parameter for link_to and would like to know the meaning of this construct. The website gives just the somewhat thin explanation Clicking this new Destroy Comment link will fire off a DELETE /articles/:article_id/comments/:id to our CommentsController, which explains the effect of this statement, but does not really explain the general mechanism behind this concept. I've looked up the API documentation at http://api.rubyonrails.org/, which gives for the second parameter of link_to the following choices (for the case that the first parameter is a string): A string containing the URL to link to, or A hash containing various options for the URL An array as parameter is not mentioned. It seems that the API documentation is not complete here. Or did I look at the wrong place? Please could someone explain this syntax to me, and also point out, where I can find a more detailed description of the API? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/778fe1221ef4104cc28d0909c40fd1c1%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Beginner's routing question: Redirecting to a different controller
I have a problem passing control from one controller to the next. Here are the details: I have a model 'Dict' with primary key :dictname. I have two controllers, named 'Login' and 'Dict'. The application starts in views/login/index.html.erb, where I have - among other stuff - an entry field for the dictname. When clicking a button, control passes to a method in login_controller.rb, where various authentification is being performed. If all checks pass, control should now be transfered to a page views/dict/manage.html.erb , and this page should receive the dictname as a parameter. Here is what I have tried so far: In routes.rb I placed an entry get 'dict/:id/manage', to: 'dict#manage' In login_controller.rb, I tried to transfer the controll with redirect_to dict_path(@dict) However, I get the error message 'undefined method dict_path' I thought that dict_path should be a helper method, which is generated out of my routes.rb . Since this method is undefined, I suspect that my routes.rb is not correct. Note that I did NOT place a resources :dicts into routes.rb, because - for the time being - I don't need yet the full set of CRUD capabilities on a Dict, so I thought I'll just start with the minimum needed, and extend over the time as necessary. If you think that this is an unwise decision, please let me know. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/b67980df9f40488cdb667561c9b24faa%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] rails generate -p complains about Spring server
Rails 4.1.1, Ruby 2.1.1, OSX 10.6 This works: rails generate model Word repr:string level:integer atari:integer triple:references This does not: rails generate model -p Word repr:string level:integer atari:integer triple:references It raises the error message: .../ruby-2.1.1/gems/spring-1.1.3/lib/spring/client/run.rb:73:in `connect_to_application': Error connecting to Spring server (RuntimeError) from /Users/fusshuhn/.rvm/gems/ruby-2.1.1/gems/spring-1.1.3/lib/spring/client/run.rb:30:in `call' From my understanding (as of 'rails generate model -h'), the purpose of -p is to just show which changes would be done, without actually changing anything (i.e. doing a dry run), so I'm surprised to get this error. What does the error mean, and why do I get it? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/053a11cb49e65dd263c0f44ee51b4c8c%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: rails generate -p complains about Spring server
Fab Forestier wrote in post #1146691: If you take a look in the helper ( rails generate model -h) the options are after attributes of your model like this rails generate model Word repr:string level:integer atari:integer triple:references -p Thanks so much! Now it's obvious... -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/7d7eebf61cbce69a692b83694f99dc50%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Please help modelling has-a-vector-of-3 relationship
In my application, I have 3 models. Let's call them X, Y and Z for brevity. Their relationship are as follows: - One X has an arbitrary number (maybe zero) items of type Y. - One Y has 2 or 3 items of type Z. Moreover, these items are *ordered*, i.e. I need to record somehow, which is the first one, which the second etc. - From a certain Z, I need to find out which Y it belongs to, and from a Y, I need to find out which X it belongs to. - When an X is deleted, the contained Y need to be destroyed too. - When an Y is deleted, the contained Z need to be destroyed too. Here is what I have so far: The mapping between X and Y is straightforward. When generating the model for Y, I included a field X:references. Within X.db, I included a has_many: :y, dependent: :destroy For the mapping between Y and Z, I didn't come up with a convincing solution. When generating the model Z, I included a field Y:references, but how do I model the 2 or 3 Z entities within Z? From a database viewpoint, I would need three fields (with different names, say z1, z2 and z3), which all contain the ID of a certain row within z. The field z3 might be NULL (in SQL terms), while z1 and z2 must always be provided. But how do I define this in the ruby generate model command? The only field type which could store a reference to another table, would be 'references', but don't see how this would help me in this case. I already thought about this workaround: I do a has_many relationship from Y to Z, and my application makes sure, that there are only 2 or 3 Z elements assigned at one time. In addition, I add to my Z table a field, which says whether it is number one, two or three within this group. This should work, but can this really be called an elegant design? -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/f1511c8936c71770b55467b512d99fd4%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] Re: Please help modelling has-a-vector-of-3 relationship
tamouse m. wrote in post #1146720: As much as I hate to say is, this *might* be a case for single table inheritance... So be it! ;-) Thank you for the confirmation. -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/777c3add61f1f430be4cc1897fc6f840%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.
[Rails] (Beginner) ActionController::UrlGenerationError - No route matches
(Using Rails 4.1.1 with Ruby 2.1.1 on Mac OSX 10.6 Snow Leopard) I'm doing a Rails tutorial (in case you are interested in: It's http://guides.rubyonrails.org/getting_started.html), and I'm stuck on the following: I create in some erb file a link using %= link_to 'Add new weird stuff', controller: new_article_path % and this raises the exception ActionController::UrlGenerationError in Articles#index No route matches {:action=index, :controller=articles/new} The helper new_article_path returns 'articles/new'. My routes are these: welcome_index GET/welcome/index(.:format) welcome#index articles GET/articles(.:format) articles#index POST /articles(.:format) articles#create new_article GET/articles/new(.:format) articles#new edit_article GET/articles/:id/edit(.:format) articles#edit article GET/articles/:id(.:format) articles#show PATCH /articles/:id(.:format) articles#update PUT/articles/:id(.:format) articles#update DELETE /articles/:id(.:format) articles#destroy root GET/welcome#index My ArticlesController class has a method 'new' with empty body. I have views/articles/new.html.erb. When I manually enter the URL http://localhost:3001/articles/new in my browser, the correct page is shown. I had expected that my link_to call() would generate a link to that very page, but instead it throws an exception. Something seems to be missing here. Where am I wrong here, and how can I fix it? (I hope the information provided is complete to answer this question). -- Posted via http://www.ruby-forum.com/. -- 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/msgid/rubyonrails-talk/9bfde5ceff8c02bcb1c82907453a2cf8%40ruby-forum.com. For more options, visit https://groups.google.com/d/optout.