Search Results

Search found 9437 results on 378 pages for 'rails newbie'.

Page 115/378 | < Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >

  • Ajax using Rails

    - by Steve
    Hi, I have a favourite and un-favourite functionality in my application and I am using jQuery. This functionality works partially. The page gets loaded, and when I click the 'favourite' button(it is inside add_favourite_div element), it sends a XHR request and the post is set as favourite. Then a new div called "remove_favourite_div" replaces its place.Now when I click the remove favourite(which is part of remove_favourite_div), it sends a normal http request inside of xhr. The structure when the page gets loaded first time <div id="favourite"> <div id="add_favourite_div"> <form method="post" id="add_favourite" action="/viewpost/add_favourite"> <div style="margin: 0pt; padding: 0pt; display: inline;"> <input type="hidden" value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" name="authenticity_token"> </div> <input type="hidden" value="3" name="Favourite[post_id]" id="Favourite_place_id"> <input type="hidden" value="2" name="Favourite[user_id]" id="Favourite_user_id"> <input type="submit" value="Favourite" name="commit"><br> </form> </div> </div> DOM after clicking on the unfavourite button <div id="favourite"> <div id="remove_favourite_div"> <form method="post" id="remove_favourite" action="/viewpost/remove_favourite"> <div style="margin: 0pt; padding: 0pt; display: inline;"> <input type="hidden" value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" name="authenticity_token"> </div> <input type="hidden" value="3" name="Favourite[post_id]" id="Favourite_place_id"> <input type="hidden" value="2" name="Favourite[user_id]" id="Favourite_user_id"> <input type="submit" value="UnFavourite" name="commit"><br> </form> </div> </div> In my application.js, I have two functions to trigger the xhr request $("#add_favourite").submit(function(){ alert("add favourite"); action = $(this).attr("action") $.post(action,$(this).serialize(),null,"script"); return false; }); $("#remove_favourite").submit(function(){ alert("remove favourite"); action = $(this).attr("action"); $.post(action,$(this).serialize(),null,"script"); return false; }); Here, when the post is initially not a favourite, favourite button is displayed and when i clicked on the button, $("#add_favourite").submit gets called and unfavourite form is displayed correctly, but now when I click on the un-favourite button, $("#remove_favourite").submit does not get called. The whole scenario is true in both ways, I mean favourite-Unfavourite and Unfavourite-favourite Can someone please help me to solve this Thanks

    Read the article

  • Rails: Generic form actions, cancel link losing `:back` on validation failure

    - by Patrick Connor
    I am trying to create a generic set of Submit, Cancel, and Destroy actions for forms. At this point, it appears that everything is working, except that I lose :back functionality then a form reloads due to validation errors. Is there a way to catch the fact that validation has failed, and in that case, keep the request.env['HTTP_REFERER'] or :back value the same without having to edit every controller? = simple_form_for @announcement do |f| = f.error_notification = f.input :message = f.input :starts_at = f.input :ends_at #submit = f.button :submit = "or " = link_to("cancel", url_for(:back)) .right - if !f.object.new_record? - resource = (f.object.class.name).downcase = link_to "destroy", url_for(:action => 'destroy'), :confirm => "Are you sure that you want to delete this #{resource}?", :method => :delete .clear .non_input #post_back_msg #indicator.inline = image_tag "indicator.gif" .inline = "Please wait..." .non_input

    Read the article

  • 2 Rails Apps, 1 Database (using Heroku)

    - by Paul A.
    I've made 2 apps, App A and App B. App A's sole purpose is to allow users to sign up and App B's purpose is to take select users from App A email them. Since App A & B were created independently & are hosted in 2 separate Heroku instances, how can App B access the users database in App A? Is there a way to push certain relevant rows from App A to App B?

    Read the article

  • How good is the Rails sanitize() method?

    - by Horace Loeb
    Can I use ActionView::Helpers::SanitizeHelper#sanitize on user-entered text that I plan on showing to other users? E.g., will it properly handle all cases described on this site? Also, the documentation mentions: Please note that sanitizing user-provided text does not guarantee that the resulting markup is valid (conforming to a document type) or even well-formed. The output may still contain e.g. unescaped ’<’, ’’, ’&’ characters and confuse browsers. What's the best way to handle this? Pass the sanitized text through Hpricot before displaying?

    Read the article

  • Locking DB w/ Large Reads (Ruby-on-Rails/Heroku)

    - by Splashlin
    Currently I have a Web API running on Heroku that is constantly writing information we're collecting from other data sources (currently theres about half a GB of data and it's growing very quickly). We're looking to add a reporting system on top of the current database that we can use to extract useful information out of the DB. The problem is that when we're running reports we're locking the DB and any other sites communicating with the DB are timing out. Does anyone have any solutions on how to solve this type of issue? Amazon RDS seems to have some interesting stuff with database replication but I don't know if that will solve my problems. Any advice would be greatly appreciated. Thanks

    Read the article

  • Deploy tracking with Ruby on Rails and Capistrano

    - by TK
    Like every commit has a reason and purpose, I think each deploy has a purpose and reason. Source code commits have a comment. But deploying doesn't have any. How do I record a reason and purpose for each deploy automatically? I need to keep a record of: Who deployed to where and what time. Why deployed? Bug fixes? Feature update? Emergency fix not on iteration plan? Which git or svn ref was used? Have anybody felt the need for this kind of system? How do you feel about my approach? How can I achieve my goal? I'm currently using Capistrano for deployment.

    Read the article

  • SEO Friendly URLs where the phrase used may change in Rails

    - by Newy
    Say I have http://www.mysite.com/I-Like-Cheeseburgers and I want that to point to Item with id 3. Sometime later, I change the name of the item, and now its http://www.mysite.com/I-Like-Hamburgers (and perhaps many more times). I want all these URLs to remain pointing to Item 3. Is it efficient to simply keep a table of [strings,item_ids] and do a lookup on this? Is there a better way?

    Read the article

  • Want to convert whole PHP script in RUBY ON RAILS

    - by user303058
    // set image quality (from 0 to 100, not applicable to gif) $imgquality = 100; // get data from $_POST or $_GET ? $data = &$_POST; // get image dimensions $width = (int) $data['width']; $height = (int) $data['height']; // create image object $img = imagecreatetruecolor($width, $height); // populate image with pixels for ($y = 0; $y < $height; $y++) { // innitialize $x = 0; // get row data $row = explode(',', $data['r'.$y]); // place row pixels $cnt = sizeof($row); for ($r = 0; $r < $cnt; $r++) { // get pixel(s) data $pixel = explode(':', $row[$r]); // get color $pixel[0] = str_pad($pixel[0], 6, '0', STR_PAD_LEFT); $cr = hexdec(substr($pixel[0], 0, 2)); $cg = hexdec(substr($pixel[0], 2, 2)); $cb = hexdec(substr($pixel[0], 4, 2)); // allocate color $color = imagecolorallocate($img, $cr, $cg, $cb); // place repeating pixels $repeat = isset($pixel[1]) ? (int) $pixel[1] : 1; for ($c = 0; $c < $repeat; $c++) { // place pixel imagesetpixel($img, $x, $y, $color); // iterate column $x++; } } } // set proper content type header('Content-type: image/'.$imgtype); header('Content-Disposition: attachment; filename="chart.'.$imgtype.'"'); // stream image $function = 'image'.$imgtype; if ($imgtype == 'gif') { $function($img); } else { $function($img, null, $imgquality); } // destroy imagedestroy($img); ?

    Read the article

  • rails belongs_to sql statement using NULL id

    - by Team Pannous
    When paginating through our Phrase table it takes very long to return the results. In the sql logs we see many sql requests which don't make sense to us: Phrase Load (7.4ms) SELECT "phrases".* FROM "phrases" WHERE "phrases"."id" IS NULL LIMIT 1 User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1 These add up significantly. Is there a way to prevent querying against null ids? This is the underlying model: class Phrase < ActiveRecord::Base belongs_to :user belongs_to :response, :class_name => "Phrase", :foreign_key => "next_id" end

    Read the article

  • Show or hide fields depending on the Acl9 role - Ruby on Rails

    - by Michaël
    Hi, I am using Acl9 to manage the roles and I want to hide the checkbox usertype if the user has the role :customer and show it if the role is :manager. I want that just the :manager can edit all the fields and some for the :customer. Thank you for your help! <h1>Editing user</h1> <% form_for(@user) do |f| %> <%= f.error_messages %> <p> <%= f.label :usertype %><br /> <%= f.check_box :usertype %> </p> <p> <%= f.label :surname %><br /> <%= f.text_field :surname %> </p> <p> <%= f.label :firstname %><br /> <%= f.text_field :firstname %> </p> <p> <%= f.label :phone %><br /> <%= f.text_field :phone %> </p> <p> <%= f.label :email %><br /> <%= f.text_field :email %> </p> <p> <%= f.label :registrationdate %><br /> <%= f.datetime_select :registrationdate %> </p> <p> <%= f.label :login %><br /> <%= f.text_field :login %> </p> <p> <%= f.label :password %><br /> <%= f.text_field :password %> </p> <p> <%= f.submit 'Update' %> </p> <% end %> <%= link_to 'Show', @user %> | <%= link_to 'Back', users_path %>

    Read the article

  • Ruby On Rails Routes

    - by Kezzer
    I can't figure out how to get the following routes. Here's an extract from my routes.rb file: map.resources :treatments map.root :controller => "home" map.connect ':controller/:action/:id' map.connect ':controller/:action/:id.:format' map.connect ':action', :controller => 'home' # replaces the need to manually map pure actions to a default controller map.resources :bookings map.resource :dashboard map.resource :home Now I do realise that the ordering matters, but I can't seem to get them to work correctly. What I want is so http://localhost:3000/bookings/new actually takes you to an action http://localhost:3000/bookings/signmeup if you're either not signed in, or haven't got a login. The problem is that if I change my routes around, when I attempt to create a new booking after I have logged in, then it doesn't POST the form submission and just takes me back to the view page. This is definitely because of the routes as if I rearrange map.resources :bookings to be before all of them, then it works. Any ideas?

    Read the article

  • Ruby on Rails Increment Counter in Model

    - by febs
    I'm attempting to increment a counter in my User table from another model. class Count < ActiveRecord::Base belongs_to :user after_create :update_count def update_count user = User.find(self.user_id) user.increment(:count) end end So when count is created the goal would be to increment a counter column for that user. Currently it refuses to get the user after creation and I get a nil error. I'm using devise for my Users Is this the right (best practice) place to do it? I had it working in the controllers, but wanted to clean it up. I'm very inexperienced with Model callbacks.

    Read the article

  • Rails: Pass association object to the View

    - by Fedyashev Nikita
    Model Item belongs_to User. In my controller I have code like this: @items = Item.find(:all) I need to have a corresponding User models for each item in my View templates. it works in controller(but not in View template): @items.each { |item| item.user } But manual looping just to build associations for View template kinda smells. How can I do this not in a creepy way?

    Read the article

  • Best Solution For Authentication in Ruby on Rails

    - by Dan Wolchonok
    I'm looking for a pre-built solution I can use in my RoR application. I'm ideally looking for something similar to the ASP.NET Forms authentication that provides email validation, sign-up controls, and allows users to reset their passwords. Oh yeah, and easily allows me to pull the user that is currently logged into the application. I've started to look into the already written pieces, but I've found it to be really confusing. I've looked at LoginGenerator, RestfulAuthentication, SaltedLoginGenerator, but there doesn't seem to be one place that has great tutorials or provide a comparison of them. If there's a site I just haven't discovered yet, or if there is a de-facto standard that most people use, I'd appreciate the helping hand.

    Read the article

  • RoR: Where is the "rails/info/properties" route defined?

    - by Dave Paroulek
    I'm running Rails 2.3.4. When I create a new rails project, the public/index.html file has a link named "About your application's environment" that points to "rails/info/properties". In dev mode, it gives a summary of the runtime environment. However, in production mode, it gives a 404 page cannot be found. Could someone point me in the direction of how and where the "rails/info/properties" route is configured? I'd just like to understand how it's set up.

    Read the article

  • Group by with ActiveRecord in Rails

    - by Adnan
    Hello, I have a the following table with rows: ================================================================ id | name | group1 | group2 | group3 | group4 | ================================================================ 1 | Bob | 1 | 0 | 0 | 1| ================================================================ 2 | Eric| 0 | 1 | 0 | 1| ================================================================ 3 | Muris | 1 | 0 | 1 | 1| ================================================================ 4 | Angela | 0 | 0 | 0 | 1| ================================================================ What would be the most efficient way to get the list with ActiveRecords ordered by groups and show their count like this: group1 (2) group2 (1) group3 (1) group4 (4) All help is appreciated.

    Read the article

  • Rails find by *all* associated tags.id in

    - by mark
    Hi Say I have a model Taggable has_many tags, how may I find all taggables by their associated tag's taggable_id field? Taggable.find(:all, :joins => :tags, :conditions => {:tags => {:taggable_id => [1,2,3]}}) results in this: SELECT `taggables`.* FROM `taggables` INNER JOIN `tags` ON tags.taggable_id = taggables.id WHERE (`tag`.`taggable_id` IN (1,2,3)) The syntax is incredible but does not fit my needs in that the resulting sql returns any taggable that has any, some or all of the tags. How can I find taggables with related tags of field taggable_id valued 1, 2 and 3? Thanks for any advice. :)

    Read the article

  • Ruby on Rails: has_many through frustrations

    - by Joe Cairns
    I'm having a frustrating problem with a has_many through: namely the fact that the through models are not created until save. Unfortunately, I need to set data on these models prior to saving the parent. Here's the loose setup: class Wtf < ActiveRecord::Base belongs_to :foo belongs_to :bar end class Bar < ActiveRecord::Base has_many :wtfs has_many :foos, :through => :wtfs end class Foo < ActiveRecord::Base has_many :wtfs has_many :bars, :through => :wtfs def after_initialize Bar.all.each do |bar| bars << bar end end end Everything is fine except that I need to access the "wtf"'s prior to save: f = Foo.new = # f.bars = [list of bars] empty list here f.wtfs = [] f.save! = true now I get stuff f.wtfs = [list of stuff] I even went so far as to explicitly create the wtfs doing this: def after_initialize Bar.all.each do |bar| wtfs << Wtf.new( :foo => self, :bar => bar, :data_i_need_to_set => 10) end end This causes the f.wtfs to be populated, but not the bars. When I save and retrieve, I get double the expected wtfs. Anyone have any ideas?

    Read the article

  • Rails rabl json format

    - by brabertaser1992
    I'm displaying data from my db in json format using rabl to parse it for android... My json looks like so: [ { "bank":{ "central_office_address":"ololo", "license":"12312312", "location_id":3, "name":"Pbank", "tax_number":"12312312", "year_of_foundation":1987 } }, { "bank":{ "central_office_address":"sdfsdf sdf", "license":"321312", "location_id":3, "name":"Bbank", "tax_number":"321321", "year_of_foundation":1999 } } ] I need my json in a format like: { "contacts": [ { "id": "c200", "name": "Ravi Tamada", "email": "[email protected]", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } }, { "id": "c201", "name": "Johnny Depp", "email": "[email protected]", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } } ] } Such data is normally parsed in java.... My rabl view: object @banks attributes :central_office_address, :license, :location_id, :name, :tax_number, :year_of_foundation How do I change its output to match the second example?

    Read the article

  • Mocking view helpers with rspec-rails 2.0.0.beta.8

    - by snl
    I am trying to mock a view helper with rspec2. The old way of doing this throws an error, complaining the template object is not defined: template.should_receive(:current_user).and_return(mock("user")) Am I missing something here, or is this not implemented in rspec2 (yet)?

    Read the article

  • Rails object based permission/authorization engine?

    - by Vlad
    Hi I want to add "Sharing documents" feature to my app, like in google documents service. As i see: User can: can list/view/create/edit/delete own documents share own document to everyone - its a public document share own document to another user with read-only access share own document to another user with read-write access view list of own documents and users to whom he gave permission to read and write view list of foreign documents view/edit foreign document with read/write permissions Please tell me, which permission/authorization solution is preffered for my task?

    Read the article

  • Writing a simple incrementer counter in rails

    - by Trip
    For every Card, I would like to attach a special number to them that increments by one. I assume I can do this all in the controller. def create @card = Card.new(params[:card]) @card.SpecNum = @card.SpecNum ++ ... end Or. I can be blatantly retarded. And maybe the best bet is to add an auto-incremement table to mysql. The problem is the number has to start at a specific number, 1020. Any ideas?

    Read the article

< Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >