Search Results

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

Page 102/378 | < Previous Page | 98 99 100 101 102 103 104 105 106 107 108 109  | Next Page >

  • Problem with returning values from a helper method in Rails

    - by True Soft
    I want to print some objects in a table having 2 rows per object, like this: <tr class="title"> <td>Name</td><td>Price</td> </tr> <tr class="content"> <td>Content</td><td>123</td> </tr> I wrote a helper method in products_helper.rb, based on the answer of this question. def write_products(products) products.map { |product| content_tag :tr, :class => "title" do content_tag :td do link_to h(product.name), product, :title=>product.name end content_tag :td do product.price end end content_tag :tr, :class => "content" do content_tag :td, h(product.content) content_tag :td, product.count end }.join end But this does not work as expected. It only returns the last node - the last <td>123</td> What should I do to make it work?

    Read the article

  • What is the proper way to specify a path to 'app' in a Rails plugin?

    - by Brian Deterling
    This question came about because the cells gem specifies template directories using File.join('app','cells'). That works fine until you run Rails as a daemon (scripts/server -d). The daemon switches directories to / which leaves the cells template paths pointing to the wrong absolute path. My solution was to set the default paths to File.join(RAILS_ROOT, 'app', 'cells'). This works in Rails, but the unit tests for the plugin fail because RAILS_ROOT isn't defined. Using File.join(File.dirname(__FILE__),'..' ... also works but requires about 6 levels of '..' which seems wrong. So my question is what is the proper way to specify the path to a directory under 'app' in a Rails plugin? Or is there something else wrong that would cause daemonizing Rails to fail to find the relative paths?

    Read the article

  • Return only the new database items since last check in Rails

    - by Smith
    I'm fairly new to Ruby, and currently trying to implement an AJAX style commenting system. When the user views a topic, all the current comments on that topic will be displayed. The user can post a comment on the page of a topic and it should automatically display without having to refresh the page, along with any new comments that have been posted since the last comment currently displayed to the user. The comments should also automatically refresh at a specified frequency. I currently have the following code: views/idea/view.html.erb <%= periodically_call_remote(:update => "div_chat", :frequency => 1, :position => "top", :url => {:controller => "comment", :action => :test_view, :idea_id => @idea.id } ) %> <div id="div_chat"> </div> views/comment/test_view.html.erb <% @comments.each do |c| %><div id="comment"> <%= c.comment %> </div> <% end %> controllers/comment_controller.rb class CommentController < ApplicationController before_filter :start_defs def add_comment @comment = Comment.new params[:comment] if @comment.save flash[:notice] = "Successfully commented." else flash[:notice] = "UnSuccessfully commented." end end def test_render @comments = Comment.find_all_by_idea_id(params[:idea_id], :order => "created_at DESC", :conditions => ["created_at > ?", @latest_time] ) @latest = Comment.find(:first, :order => "created_at DESC") @latest_time = @latest.created_at end def start_defs @latest = Comment.find(:first, :order => "created_at ASC") @latest_time = @latest.created_at end end The problem is that every time periodically_call_remote makes a call, it returns the entire list of comments for that topic. From what I can tell, the @latest_time gets constantly reset to the earliest created_at, rather than staying updated to the latest created_at after the comments have been retrieved. I'm also not sure how I should directly refresh the comments when a comment is posted. Is it possible to force a call to periodically_call_remote on a successful save?

    Read the article

  • Dynamic select menu Rails, Javascript HABTM

    - by Jack
    Hi, I am following a tutorial in one of Ryan Bates' Railscasts here. Basically I want a form where there are 2 drop down menus, the contents of one are dependent on the other. I have Years and Courses, where Years HABMT Courses and Courses HABTM Years. In the tutorial, the javascript is as follows: var states = new Array(); <% for state in @states -%> states.push(new Array(<%= state.country_id %>, '<%=h state.name %>', <%= state.id %>)); <% end -%> function countrySelected() { country_id = $('person_country_id').getValue(); options = $('person_state_id').options; options.length = 1; states.each(function(state) { if (state[0] == country_id) { options[options.length] = new Option(state[1], state[2]); } }); if (options.length == 1) { $('state_field').hide(); } else { $('state_field').show(); } } document.observe('dom:loaded', function() { countrySelected(); $('person_country_id').observe('change', countrySelected); }); Where I guess country has many states and state belongs to country. I think what I need to do is edit the first for statement to somehow loop through all of the courses for each year_id, but don't know how to do this. Any ideas? Thanks

    Read the article

  • Rails - Seeking a Dry authorization method compatible with various nested resources

    - by adam
    Consensus is you shouldn't nest resources deeper than 1 level. So if I have 3 models like this (below is just a hypothetical situation) User has_many Houses has_many Tenants and to abide by the above i do map.resources :users, :has_many => :houses map.resorces :houses, :has_many => :tenants Now I want the user to be able edit both their houses and their tenants details but I want to prevent them from trying to edit another users houses and tenants by forging the user_id part of the urls. So I create a before_filter like this def prevent_user_acting_as_other_user if User.find_by_id(params[:user_id]) != current_user() @current_user_session.destroy flash[:error] = "Stop screwing around wiseguy" redirect_to login_url() return end end for houses that's easy because the user_id is passed via edit_user_house_path(@user, @house) but in the tenents case tenant house_tenent_path(@house) no user id is passed. But I can get the user id by doing @house.user.id but then id have to change the code above to this. def prevent_user_acting_as_other_user if params[:user_id] @user = User.find(params[:user_id] elsif params[:house_id] @user = House.find(params[:house_id]).user end if @user != current_user() #kick em out end end It does the job, but I'm wondering if there is a more elegant way. Every time I add a new resource that needs protecting from user forgery Ill have to keep adding conditionals. I don't think there will be many cases but would like to know a better approach if one exists.

    Read the article

  • Rails: Auto-Detecting Database Adapter

    - by Dex
    The new version of the ar-extensions gem requires that you load the appropriate adapter yourself. On my development side I use mysql, however Heroku uses PostgreSQL. For example, on my development side I need to do this: require 'ar-extensions/adapters/mysql' require 'ar-extensions/import/mysql' How can I audo-detect which adapter to use?

    Read the article

  • Ruby on Rails activerecord find average in one sql and Will_Paginate

    - by Darkerstar
    Hi all I have the following model association: a student model and has_many scores. I need to make a list showing their names and average, min, max scores. So far I am using student.scores.average(:score) on each student, and I realise that it is doing one sql per student. How can I make the list with one joined sql? Also how would I use that with Will_Paginate plugin? Thank you

    Read the article

  • (Rails) Assert_Select's Annoying Warnings

    - by CalebHC
    Does anyone know how to make assert_select not output all those nasty html warnings during a rake test? You know, like this stuff: .ignoring attempt to close body with div opened at byte 1036, line 5 closed at byte 5342, line 42 attributes at open: {"class"=>"inner02"} text around open: "</script>\r\t</head>\r\t<body class=\"inner02" text around close: "\t</div>\r\t\t\t</div>\r\t\t</div>\r\t</body>\r</ht" Thanks

    Read the article

  • work with rescue in Rails

    - by Adnan
    Hi, I am working with the following piece; def index @user = User.find(params[:id]) rescue flash[:notice] = "ERROR" redirect_to(:action => 'index') else flash[:notice] = "OK" redirect_to(:action => 'index') end Now I either case whether I have a correct ID or not, I am always getting "OK" in my view, what am I doing wrong? I need that when I have no ID in the DB to show "ERROR". I have also tried to use rescue ActiveRecord::RecordNotFound but same happens. All help is appreciated.

    Read the article

  • Rails ActiveRecord: Find All Users Except Current User

    - by SingleShot
    I feel this should be very simple but my brain is short-circuiting on it. If I have an object representing the current user, and want to query for all users except the current user, how can I do this, taking into account that the current user can sometimes be nil? This is what I am doing right now: def index @users = User.all @users.delete current_user end What I don't like is that I am doing post-processing on the query result. Besides feeling a little wrong, I don't think this will work nicely if I convert the query over to be run with will_paginate. Any suggestions for how to do this with a query? Thanks.

    Read the article

  • Changing the id parameter in Rails routing

    - by japancheese
    Hello, Using rails3 new routing system, is it possible to change the default :id parameter resources :users, :key => :username come out with the following routes /users/new /users/:username /users/:username/edit ...etc I'm asking because although the above example is simple, it would be really helpful to do in a current project I'm working on. Is it possible to change this parameter, and if not, is there a particular reason as to why not?

    Read the article

  • Rails ActiveRecord conditions

    - by xpepermint
    Is there a way to create a condition like this? @products = Product.find(:all, :limit => 5, :conditions => { :products => { :locale => 'en', :id NOT '1' }, :tags => { :name => ['a','b']}) I would like to list all products not including product 1. Thx.

    Read the article

  • rails check_box_tag value is NULL

    - by looloobs
    Hi I am not sure why I am having this problem, maybe I am using the check_box_tag incorrectly. I have a form that is used to send an email message. You are supposed to be able to choose one or more boxes that represent different groups of people. <%= check_box_tag (:bcc_email, value = @spouses) %> <%= f.label :bcc_email, "Company Spouses" %><br /> <%= check_box_tag (:bcc_email, value = @soldiers) %> <%= f.label :bcc_email, "Company Soldiers" %><br /> The values are an array of email addresses. Those work fine, I have had them functioning as drop down menus for sometime. When I look at the HTML page source the values are there, they are just not being passed along with the create method. Any ideas?

    Read the article

  • Rails, search item in different model?

    - by Danny McClelland
    Hi Everyone, I have a kase model which I am using a simple search form in. The problem I am having is some kases are linked to companies through a company model, and people through a people model. At the moment my search (in Kase model) looks like this: # SEARCH FACILITY def self.search(search) search_condition = "%" + search + "%" find(:all, :conditions => ['jobno LIKE ? OR casesubject LIKE ? OR transport LIKE ? OR goods LIKE ? OR comments LIKE ? OR invoicenumber LIKE ? OR netamount LIKE ? OR clientref LIKE ? OR kase_status LIKE ? OR lyingatlocationaddresscity LIKE ?', search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition, search_condition]) end What I am trying to work out, is what condition can I add to allow a search by Company or Person to show the cases they are linked to. @kase.company.companyname and company.companyname don't work :( Is this possible? Thanks, Danny

    Read the article

  • functional test for rails controller privaet method

    - by mohit
    I have a private method in my controller. which is used for some database update. this method i am calling from another controller method. and it works fine. But when i am trying to write a test case for that method then It is tripping on accessing (session variable and params) in my functional all other methods are working fine the problem is only with private method? In my setup method in functional test, I am setting session also.?

    Read the article

  • Multiple forms using Rails & jQuery & AJAX

    - by biggie8199
    I have multiple coupons on a page and I'm trying to get comments to work on each coupon. So for each coupon i have a comments form. Im using jQuery + Ajax to accomplish this. Here's what my code looks like. Coupon Page <p>Comments:</p> <% form_for(@comment) do |f| %> <%= f.label :body %><br /><%= f.text_field :body, :size => "24" %> <%= f.hidden_field :coupon_id, :value => coupon.id %> <%= f.submit "Save" %> <% end %> Application.js jQuery.ajaxSetup({ 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} }) jQuery.fn.submitWithAjax = function() { this.submit(function() { $.post(this.action, $(this).serialize(), null, "script"); return false; }) return this; }; $(document).ready(function() { $("#new_comment").submitWithAjax(); }) I tried changing the jQuery selector to a class $(".new_comment").submitWithAjax(); Thinking that would work, now all the submit buttons work, however it posts only the first form on the page. What can I change to make it so ajax submits the correct form and not the first one?

    Read the article

  • Help me understand Rails eager loading

    - by aaronrussell
    I'm a little confused as to the mechanics of eager loading in active record. Lets say a Book model has many Pages and I fetch a book using this query: @book = Book.find book_id, :include => :pages Now this where I'm confused. My understanding is that @book.pages is already loaded and won't execute another query. But suppose I want to find a specific page, what would I do? @book.pages.find page_id # OR... @book.pages.to_ary.find{|p| p.id == page_id} Am I right in thinking that the first example will execute another query, and therefore making the eager loading pointless, or is active record clever enough to know that it doesn't need to do another query? Also, my second question, is there an argument that in some cases eager loading is more intensive on the database and sometimes multiple small queries will be more efficient that a single large query? Thanks for your thoughts.

    Read the article

  • Why MyModel.all works in Rails ?

    - by AntonAL
    Hi, i don't understand this little thing: Suppose, we have "Person" model class Person < ActiveRecord::Base end Why Person.all works ? Person.all.each { |p| do_something } This syntax tells us, that we have Person class-object instanciated somewhere ? Or is it some convention over configuration case ?

    Read the article

  • Rails Habtm with a field

    - by moshimoshi
    Hello, Is that possible to have a field in a has and belongs to many table? Just like favorite: create_table :messages_users, :id => false, :force => true do |t| t.integer :message_id, :null => false t.integer :user_id, :null => false t.boolean :favorite, :null => false t.timestamps end I saw timestamps works well, thanks to ActiveRecord. But when I try to add favorite into the table and then I try: Message.first.users << User.first Then I get this error message: ActiveRecord::StatementInvalid: SQLite3::SQLException: messages_users.favorite may not be NULL: INSERT INTO "messages_users" ("created_at", "message_id", "updated_at", "user_id") VALUES ('''2010-05-27 06:07 :50.721512''', 1, '''2010-05-27 06:07:50.721512''', 1) I would like to use a habtm, I don't like has_many foo though bar association :) Is that possible? Thanks a lot.

    Read the article

  • stripe payment issue ruby on rails

    - by Admir Huric
    So I have made a stripe payment option in my app. When I click the button pay now, it shows me that the payment is successful. and when I go to my stripe account and go to stripe-test and check logs, I can see my test payment with the code 200 OK. But this payment doesn't show in stripe-test events, or in stripe-test payments. Are the payments from logs processed the next day or am I doing something wrong? def charge Stripe.api_key = "some_test_api_key" customer = Stripe::Customer.retrieve(stripe_customer_id) if stripe_customer_id.nil? Stripe::Charge.create( :amount => 2500, :currency => "cad", :customer => stripe_customer_id, :description => "Usage charges for #{name}" ) end rescue Stripe::StripeError => e logger.error "Stripe Error: " + e.message errors.add :base, "Unable to process charge. #{e.message}." false end

    Read the article

  • Capistrano 3, Rails 4, database configuration does not specify adapter

    - by Kazmin
    When I start cap production deploy it fails like this: DEBUG [4ee8fa7a] Command: cd /home/deploy/myapp/releases/releases/20131025212110 && (RVM_BIN_PATH=~/.rvm/bin RAILS_ENV= ~/.rvm/bin/myapp_rake assets:precompile ) DEBUG [4ee8fa7a] rake aborted! DEBUG [4ee8fa7a] database configuration does not specify adapter You can see that "RAILS_ENV=" is actually empty and I'm wondering why that might be happening? I assume that this is the reason for the latter error that I don't have a database configuration. The deploy.rb file is below: set :application, 'myapp' set :repo_url, '[email protected]:developer/myapp.git' set :branch, :master set :deploy_to, '/home/deploy/myapp/releases' set :scm, :git set :devpath, "/home/deploy/myapp_development" set :user, "deploy" set :use_sudo, false set :default_env, { rvm_bin_path: '~/.rvm/bin' } set :keep_releases, 5 namespace :deploy do desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do # Your restart mechanism here, for example: within release_path do execute " bundle exec thin restart -O -C config/thin/production.yml" end end end after :restart, :clear_cache do on roles(:web), in: :groups, limit: 3, wait: 10 do within release_path do end end end after :finishing, 'deploy:cleanup' end?

    Read the article

  • Rails 2.3: How to create this SQL into a named_scope

    - by randombits
    Having a bit of difficulty figuring out how to create a named_scope from this SQL query: select * from foo where id NOT IN (select foo_id from bar) AND foo.category = ? ORDER BY RAND() LIMIT 1; Category should be variable to change. What's the most efficient way the named_scope can be written for the problem above?

    Read the article

  • Creating records using RJS in rails

    - by Elliot
    Hey Everyone, so I've watched http://railscasts.com/episodes/43-ajax-with-rjs but I have a question: In my view I have the following: <div id="testly"> <%= render :partial => "test" %> </div> This works. Using create.rjs to change the content in this div, I have the following in my create.rjs file: page.replace_html :testly, :partial = 'test' Simply put, this should just refresh the partial right? But its not working... Would love any suggestions!

    Read the article

  • jquerry in rails

    - by Matthias Günther
    I'm iteration over records and want to create the toggle-options for records but I can't replace the div-id with the records: <% for bill in @bills % <% tmp = "test"% <%= link_to '&raquo now','#', :onclick = '$("#{tmp}").toggle();' % Instead of getting: &raquo now I'm getting: &raquo now So he isn't evaluation the ruby variable in the string. How can I do this? Thanks for your help and I'm new in jquerry.

    Read the article

< Previous Page | 98 99 100 101 102 103 104 105 106 107 108 109  | Next Page >